I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
warning about an illegal escape sequence.
I am using the Visual C++ 6.0 compiler.
A one-off solution could be to print it out as a string literal as:
char* s = 0;
s = "%f";
printf("%s\n", s);
But that'd work only for this format. I want a flexible solution since
I want to print out many of these formats as literals such as:
"%2.8f"
"%14.3f"
"%.9f"
etc. 4 8161
On Jun 16, 3:31 pm, Mukesh_Singh_N. ..@yahoo.com wrote:
I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
warning about an illegal escape sequence.
I am using the Visual C++ 6.0 compiler.
A one-off solution could be to print it out as a string literal as:
char* s = 0;
s = "%f";
printf("%s\n", s);
But that'd work only for this format. I want a flexible solution since
I want to print out many of these formats as literals such as:
"%2.8f"
"%14.3f"
"%.9f"
etc.
For instance, I could also use:
puts, or
putch, or
putchar, or
putche
but I want to only use printf because I am practicing. Suggestions,
please. Mu************* **@yahoo.com wrote:
I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
printf("%%f\n") ;
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
warning about an illegal escape sequence.
I am using the Visual C++ 6.0 compiler.
A one-off solution could be to print it out as a string literal as:
char* s = 0;
s = "%f";
printf("%s\n", s);
But that'd work only for this format. I want a flexible solution since
I want to print out many of these formats as literals such as:
"%2.8f"
"%14.3f"
"%.9f"
printf("%s\n", "%2.8f");
printf("%s\n", "%14.3f");
printf("%s\n", "%.9f");
would all work.
On Jun 16, 3:36 pm, Harald van D k <true...@gmail. comwrote:
Mukesh_Singh_N. ..@yahoo.com wrote:
I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
printf("%%f\n") ;
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
warning about an illegal escape sequence.
I am using the Visual C++ 6.0 compiler.
A one-off solution could be to print it out as a string literal as:
char* s = 0;
s = "%f";
printf("%s\n", s);
But that'd work only for this format. I want a flexible solution since
I want to print out many of these formats as literals such as:
"%2.8f"
"%14.3f"
"%.9f"
printf("%s\n", "%2.8f");
printf("%s\n", "%14.3f");
printf("%s\n", "%.9f");
would all work.- Hide quoted text -
- Show quoted text -
Thanks very much, friend. I almost forgot about the "%%" format
specifier. I had seen a C reference page mention it long ago. I can't
find it now. Can you please point me to a reference page that explains
it?
On Jun 16, 3:45 pm, Mukesh_Singh_N. ..@yahoo.com wrote:
On Jun 16, 3:36 pm, Harald van D k <true...@gmail. comwrote:
Mukesh_Singh_N. ..@yahoo.com wrote:
I am practicing printf formatting options. I want to print out a
string literal as a raw string as opposed to its special meaning. For
e.g I want to print out the "%f" part in:
printf("%f\n");
printf("%%f\n") ;
literally as "%f" rather than a zero value floating point/constant
double (0.000000).
I tried to escape the % sign but the compiler complained with a
warning about an illegal escape sequence.
I am using the Visual C++ 6.0 compiler.
A one-off solution could be to print it out as a string literal as:
char* s = 0;
s = "%f";
printf("%s\n", s);
But that'd work only for this format. I want a flexible solution since
I want to print out many of these formats as literals such as:
"%2.8f"
"%14.3f"
"%.9f"
printf("%s\n", "%2.8f");
printf("%s\n", "%14.3f");
printf("%s\n", "%.9f");
would all work.- Hide quoted text -
- Show quoted text -
Thanks very much, friend. I almost forgot about the "%%" format
specifier. I had seen a C reference page mention it long ago. I can't
find it now. Can you please point me to a reference page that explains
it?- Hide quoted text -
- Show quoted text -
OK, I got it. http://www.cppreference.com/stdio/printf.html
Thanks very much again. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Don Starr |
last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string
(including nul), or the size of a pointer?
For example, assuming a char is 1 byte and a char * is 4 bytes, should the following yield 4, 5, of
something else? (And, if something else, what determines the result?)
char x = "abcd";
printf( "%d\n", sizeof( x ) );
-Don
|
by: al |
last post by:
char s = "This string literal";
or
char *s= "This string literal";
Both define a string literal. Both suppose to be read-only and not to be
modified according to Standard. And both have type of "const char *".
Right? But why does the compiler I am using allow s to be modified, instead
of generating compile error?
|
by: Janice |
last post by:
char* line = "abcd";
How to convert the line to upper case and print?
Any option for printf to do this?
Thanx
|
by: teachtiro |
last post by:
Hi,
'C' says \ is the escape character to be used when characters are
to be interpreted in an uncommon sense, e.g. \t usage in printf(),
but for printing % through printf(), i have read that %% should be used.
Wouldn't it have been better (from design perspective) if the same
escape character had been used in this case too.
Forgive me for posting without verfying things with any standard
compiler, i don't have the means for now.
|
by: junky_fellow |
last post by:
what would be the output for the following piece of code ?
if ( "hello" == "hello" )
printf("True\n");
else
printf("False\n");
What is the reason for that ?
| |
by: copx |
last post by:
Can you / are you supposed to free() string literals which are no longer
needed?
In my case I've menu construction code that looks like this:
menu_items = list_new();
list_add(menu_items, "Item 1");
list_add(menu_items, "Item 2");
list_add(menu_items, "Item 3");
menu_create(menu_items, false)
|
by: Anne DeBlois |
last post by:
Hi,
I am currently testing the printing features of Visual Studio 2005 (VB.NET)
We want to release a database application that prints label pages. The
labels must contain a picture box.
I found this code to print an image:
e.Graphics.DrawImage(Image.FromFile("c:\\dev\\Projects\\Impression\\merci.png"),
20, 750)
|
by: Pedro Pinto |
last post by:
Hi there!
I'm creating a function that copies some information to a buffer and
enters a delimiter string "//" between results.
My issue here is when i print the buffer it appears this weird result:
cod : 2
id : 20
Buffer is
|
by: lithiumcat |
last post by:
Hi,
I'm not yet very confident in my use of standard terminology, so
please be kind if I'm mis-calling something, I will do my best no to
make it again once pointed out.
I'm wondering what is the lifetime or a compile-time string constant,
I think that is what is called the storage duration of a string
litteral.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |