Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print %s in C?

Tags:

c

printf

I want to print "%SomeString%" in C.

Is this correct?

printf("%%s%",SomeString);
like image 874
user299757 Avatar asked Jun 15 '10 06:06

user299757


People also ask

How does %s work in C?

%c deals with a char (that is, a single character), whereas %s deals with a char * (that is, a pointer to an array of characters, hopefully null-terminated).

What is %d %s %F in C?

It is a way to tell the compiler what type of data is in a variable during taking input using scanf() or printing using printf(). Some examples are %c, %d, %f, etc. The format specifier in printf() and scanf() are mostly the same but there is some difference which we will see.


2 Answers

No, %% outputs %, so the right syntax is:

printf("%%%s%%",string);
like image 106
bezmax Avatar answered Sep 19 '22 20:09

bezmax


No.

Use %%%s%%

like image 43
Pavel Radzivilovsky Avatar answered Sep 20 '22 20:09

Pavel Radzivilovsky