DoggyDoo
DoggyDoo

Reputation: 63

" escape sequence in C?

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

Answers (4)

Ruel
Ruel

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

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84159

The character '"', ASCII code 34. "In a string literal you escape it like \" this".

Upvotes: 0

Andrew Cooper
Andrew Cooper

Reputation: 32576

You want to look for "\""

Upvotes: 1

James McNellis
James McNellis

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

Related Questions