0

Hello! Why does fgets inserts also a new line character inside string?

Can someone explan me why when i use fgets to read a string from a file, it stores the data but also a new line character? When i print, lets say, 2 names with printf like this printf("%s", john); printf("%s", mary); The output is: John Mary But when i print like this: printf("%s\n", john); printf("%s\n", mary); The output is: John Mary Like this Many thanks

6th May 2019, 8:29 PM
Emanuel Terteș
Emanuel Terteș - avatar
2 ответов
+ 1
Thanks to all of you so much. It makes sense now
7th May 2019, 6:51 AM
Emanuel Terteș
Emanuel Terteș - avatar
0
\n is what is creating your newline. That is called an escape sequence.
7th May 2019, 2:47 AM
Choe
Choe - avatar