 | 
June 16th, 2008, 10:07 AM
| | Member | | Join Date: Jun 2008 Location: Igualada (Barcelona) Age: 29
Posts: 85
| | printf of the "%d" string
How to printf the string "%d" itself?
I wonder how should I escape the %, since I see no escape char for % (in http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.1.html)
Thanks!
| 
June 16th, 2008, 10:36 AM
|  | AdministratorVoR | | Join Date: Feb 2006 Location: South West UK
Posts: 5,309
| |
There is not escape code for % because it doesn't need one. However there is a format code for % because in the context of a printf it does need one.
Read this: http://www.acm.uiuc.edu/webmonkeys/b...2.html#printf] | 
June 17th, 2008, 02:03 AM
|  | Expert | | Join Date: Mar 2007 Location: Chennai Age: 29
Posts: 1,159
| |
To print % you should use % as the escape sequence.
Code will be
will print %
Raghu
| 
June 26th, 2008, 05:57 PM
| | Member | | Join Date: Mar 2007
Posts: 39
| |
char a[3]="%d";
printf("%s",a);
by using above two lines u can print %d itself
| 
June 27th, 2008, 02:35 AM
|  | Expert | | Join Date: Mar 2007 Location: Chennai Age: 29
Posts: 1,159
| | Quote: |
Originally Posted by shivapadma char a[3]="%d";
printf("%s",a);
by using above two lines u can print %d itself |
I think the %% option would be much easier as u need not declare the local variable.
Raghuram
| 
June 27th, 2008, 08:23 AM
| | Member | | Join Date: Jun 2008 Location: Igualada (Barcelona) Age: 29
Posts: 85
| |
Yep,
In the end I did something like
It was meant to construct the string to pass later on to an fscanf() while reading a file.
Thanks,
| 
June 30th, 2008, 02:11 AM
|  | Expert | | Join Date: Mar 2007 Location: Chennai Age: 29
Posts: 1,159
| | Quote: |
Originally Posted by jorba101 Yep,
In the end I did something like
It was meant to construct the string to pass later on to an fscanf() while reading a file.
Thanks, |
Hi,
You want to print % to console or have the % in a string to pass it to another function?
Raghu
| 
June 30th, 2008, 07:16 AM
| | Member | | Join Date: Jun 2008 Location: Igualada (Barcelona) Age: 29
Posts: 85
| |
I pass it to another function. Actually I was using sprintf() for that.
| 
July 3rd, 2008, 02:33 AM
|  | Expert | | Join Date: Mar 2007 Location: Chennai Age: 29
Posts: 1,159
| | Quote: |
Originally Posted by jorba101 I pass it to another function. Actually I was using sprintf() for that. | If u are using sprintf then u can follow the same idea -
char arr[100];
-
sprinf(arr,"%%");
-
-
Then u can pass arr to the function u are using.
Raghu
|  |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|