standard c library for escaping a string

前端 未结 7 1946
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 17:51

Is there a standard C library function to escape C-strings?

For example, if I had the C string:

char example[] = \"first line\\nsecond line: \\\"inne         


        
7条回答
  •  感情败类
    2020-12-10 18:06

    while(*src++)
    {
      if(*src == '\\' || *src == '\"' || *src == '\'')
        *dest++ = '\\';
    
      *dest++ = *src++;
    }
    

提交回复
热议问题