473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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!
Jun 16 '08 #1
8 2191
Banfa
9,065 Expert Mod 8TB
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]
Jun 16 '08 #2
gpraghuram
1,275 Expert 1GB
To print % you should use % as the escape sequence.
Code will be
Expand|Select|Wrap|Line Numbers
  1. printf("%%");
  2.  
will print %

Raghu
Jun 17 '08 #3
char a[3]="%d";
printf("%s",a);

by using above two lines u can print %d itself
Jun 26 '08 #4
gpraghuram
1,275 Expert 1GB
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
Jun 27 '08 #5
Yep,

In the end I did something like

Expand|Select|Wrap|Line Numbers
  1. printf("%%d");
It was meant to construct the string to pass later on to an fscanf() while reading a file.

Thanks,
Jun 27 '08 #6
gpraghuram
1,275 Expert 1GB
Yep,

In the end I did something like

Expand|Select|Wrap|Line Numbers
  1. printf("%%d");
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
Jun 30 '08 #7
I pass it to another function. Actually I was using sprintf() for that.
Jun 30 '08 #8
gpraghuram
1,275 Expert 1GB
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

Expand|Select|Wrap|Line Numbers
  1. char arr[100];
  2. sprinf(arr,"%%");
  3.  
  4.  
Then u can pass arr to the function u are using.


Raghu
Jul 3 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
8
by: baumann | last post by:
hi all, i hope printf("%#04x\n", 0); will output 0x00, but visual c++ studio 6 outputs 0000. how can i get 0x00? thanks
9
by: geek | last post by:
Hi all, Why does a printf("%d") statement prints this as output and when I do printf("%c") it doesn't print anything. -13361016 Any help would be appreciated. Thanks,
2
by: Robin Tucker | last post by:
Given the need to (possibly) alter the position of various elements in a string due to localisation, is it possible to build a string using a "printf" style function, such that the source string...
2
by: Jude | last post by:
here is the source code: #include<stdio.h> int main() { float f; scanf("%d%f",&f); printf("The float is %10.5f\n",f); return 0; } when I input 12345.11111,the output is 12345.11133.
19
by: v4vijayakumar | last post by:
why the following statement dumps the core(Segmentation fault)? printf("%s\n", __FILE__);
10
by: lovecreatesbeauty | last post by:
Is parameter type conversion required for the 2nd argument on printf("%p", (void *)&i); ? But one would never call memcpy like: memcpy((void *)pi, (void *)pj, sizeof *pj); /*memcpy((void *)pi,...
16
by: Gernot Frisch | last post by:
Hi, class MyString { char* m_data; public: MyString(const char* c) { m_data = new char; strcpy(m_data, c);
3
by: Ioannis Vranos | last post by:
Is printf("%ls") for printing wchar_t strings defined in C90, or it was added in C95?
12
by: Pietro Cerutti | last post by:
Dear all, Consider: include <stdio.h> int main(void) { printf("%d%d%d"); return (0); }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.