Hello! Why does fgets inserts also a new line character inside string? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
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 Respostas
+ 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