Did you literally type \ , then n ?
If so, he literally placed \ , and then n on your line, as if you had done the following:
char c[] = "abc\\nabc";
This is logically not a newline, but rather <<20> followed by n .
If you want to support escape sequences in user input, you will need to process any user input to create the appropriate sequence output.
for (i = 0, j = 0; c[i] != 0; ++i, ++j) { if (c[i] == '\\' && c[i+1] != 0) { switch(c[++i]) { case 'n': c[j] = '\n'; break; case '\\': c[j] = '\\'; break; default: c[j] = ' '; break; } } else { c[j] = c[i]; } } c[j] = 0;
source share