Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping an apostrophe in a character literal

Tags:

c++

escaping

Could you please tell me how can one escape an apostrophe.

I need it to process non apostrophe characters through file operations so when I encounter an apostrophe(') I can't just give ch!='''. It doesn't work. Could you please tell me the right format. Thank you..:)

like image 608
boddhisattva Avatar asked Mar 10 '10 04:03

boddhisattva


2 Answers

Use \', for example:

if ( ch != '\'' )

\' is an escape sequence for the apostrophe.

Google for "escape sequence" to know more about it.

like image 123
raj Avatar answered Nov 19 '22 23:11

raj


You can escape a single quote as

'\''

for example

while(*p && *p != '\'') p++;

This is an escape sequence; the backslash tells the compiler that following ' normal character, and not as one of the single quotes that you surround a character with.

like image 42
Daniel LeCheminant Avatar answered Nov 19 '22 22:11

Daniel LeCheminant