0
While using scanf it works fine but when I use fgets instead of scanf it only returns 1.
10 Réponses
+ 2
Line 16:
Insert a space after the %d specifier to prevent the line break character '\n' after the input number from getting left behind in the input stream. It's that '\n' that is read by fgets(), and it's also the reason why you got 1 as length of input.
scanf( "%d ", &n );
Also, since you define <str> size was <n> characters, I would recommend to use <n> as the second argument to fgets() call at line 23, to be safe. So fgets() reads in accordingly to <str> size.
fgets( str, n, stdin );
+ 1
Your question is not clear rewrite again with more discription
+ 1
You did a lot of extra. I also had issues when '\n' character was in the input. Either way, see this
https://code.sololearn.com/c20lsB5Q6gp3/?ref=app
+ 1
Thanks everyone I have solved😊
0
I mean fgets instead of scanf, bcz of buffer overflow.
0
Yes, i did
0
And thanks for this detailed explanation