So I want to check if someone enters: \\n
(\'\\\'
and then \'n\'
) from the keyboard to a string, so I\'m doing something like this:
you use another \
if ( str[i] == '\\' && str[i+1] == 'n');
The escape sequence for an actual backslash is \\
, e.g.
char c = getchar();
if(c == '\\')
... stuff ...
Instead of escape characters you can use the ASCII values like this
if ((str[i] == 92) && (str[i+1] == 'n'))
;
You have to escape \
by doubling it:
if ( ((str[i] == '\\') && (str[i+1] == 'n')) ){
}
compare the \ like this.
if ((str[i] == '\\') && (str[i+1] == 'n'))
because we have to escape the escape sequence \.
if user enter like \
and n
using keyboard .
then try like this
if(str[i] == '\\' && str[i+1] == 'n')
As \
is represented by \\
, so use \\
instead of \
to check.