+ 1

Help with this C code.

I have this code: char name[50]; fgets(name, 50, stdin); printf("your name %s is ugly", name); input: Frank output: your name Frank is ugly. why the output has a new line? how can I avoid the new line? I want to print the name in the same line, but I don't know how when I use fgets.

1st Sep 2018, 5:56 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
5 Réponses
+ 1
Tind Yes you have right... Im keep to old standards... I have to update myself 😀
1st Sep 2018, 6:58 AM
KrOW
KrOW - avatar
0
Because fgets INCLUDE the newline in your string (if present) http://www.cplusplus.com/reference/cstdio/fgets/ You can use scanf or gets for that
1st Sep 2018, 6:11 AM
KrOW
KrOW - avatar
0
Tind I see, but by doing that I can eliminate the new line? how can I do that? I'm learning C and I don't know how to implement it
1st Sep 2018, 4:41 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar