Could someone explain the following codes
#include<stdio.h>
main()
{
char c[]="abc\nabc";
puts(c);
}
This code as expected generates :
abc
abc
But when i try to take the same string as an input from the user,
#include<stdio.h>
main()
{
char c[]="abc\nabc";
gets(c); // i type in "abc\nabc"
puts(c);
}
This code generates :
abc\nabc
How can i make the program read the newline character correctly ?
Did you literally type
\thenn?If so, it literally placed a
\and then anin your string, as if you did the following:This is logically not a newline character, but rather a
\followed by an.If you would like to support escape sequences in user input, you’ll need to post-process any user input to create the appropriate escape sequences.