14th Apr 2020, 12:26 PM
Dipra Irham
Dipra Irham - avatar
3 Answers
+ 2
Simply change scanf( "%d", &dig ); to scanf( "%d\n", &dig); The problem here is that scanf() leaves the newline character in the input buffer, which is then consumed by the fgets() call, making it store that newline character in the string and then stop. Changing the format specifier will make scanf() extract the newline character as well, without affecting "digit".
14th Apr 2020, 2:56 PM
Shadow
Shadow - avatar
+ 1
logic wise: why is dig++ in line 8? I removed it and got correct output.
14th Apr 2020, 3:08 PM
minirkk
minirkk - avatar
+ 1
Thanks Shadow and RKK for the correction
14th Apr 2020, 4:24 PM
Dipra Irham
Dipra Irham - avatar