+ 3

Why this c code is not working properly?

Sometimes this code leaving the get, scanf functions lines and sometimes giving garbage output values.why can anyone explain this. https://code.sololearn.com/c6FyR4ro5cY0/?ref=app

8th Oct 2019, 12:00 PM
Maninder $ingh
Maninder $ingh - avatar
2 Antworten
+ 2
Because arrays start at 0, and you were inconsistent with your starting index `int i=1;` on line 18 while `int i=0;` on line 30. If you decide to start at 0 remember to change the end condition as well.
8th Oct 2019, 12:57 PM
jtrh
jtrh - avatar
+ 3
jtrh and by adding fflush(stdin); Line after scanf function and before gets function help to not leaving the gets line. finally i solve it.
9th Oct 2019, 12:48 AM
Maninder $ingh
Maninder $ingh - avatar