Reputation: 63
What is the escape sequence for ' " ' in C? In other words, how can i ask a while-statement to search for an occurance of ' " '?
Upvotes: 0
Views: 837
Reputation: 15780
Use strchr()
from string.h
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string with \" another \"";
char * pch;
printf ("Looking for the '\"' character in: %s ...\n",str);
pch=strchr(str,'"');
while (pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'\"');
}
return 0;
}
Upvotes: 1
Reputation: 84159
The character '"'
, ASCII code 34. "In a string literal you escape it like \" this"
.
Upvotes: 0
Reputation: 355019
In a character constant, you don't need to escape the "
character; you can simply use '"'
.
In a string literal, you do need to escape the "
character since it's the delimiter; you do this by prefixing it with a backslash ("\""
).
Note that you can escape the "
character in a character constant ('\"'
); it's just not necessary.
Upvotes: 11