“C中的逃逸序列?

时间:2010-10-07 03:47:54

标签: c string

C中'''的转义序列是什么?换句话说,我怎么能用while语句来搜索'''的出现?

4 个答案:

答案 0 :(得分:11)

在字符常量中,您不需要转义"字符;您只需使用'"'

在字符串文字中,您需要转义"字符,因为它是分隔符;你这样做的前缀是反斜杠("\"")。

请注意,您可以在字符常量(")中转义'\"'字符;它没有必要。

答案 1 :(得分:1)

您想要查找"\""

答案 2 :(得分:1)

使用strchr()

中的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;
}

答案 3 :(得分:0)

字符'"',ASCII码34. "In a string literal you escape it like \" this"

相关问题