+ 1
why doesn't this store the number of kms in the struc?
4 Answers
+ 4
The scanf() in line 14 leaves a newline in the input buffer. After that, the next fgets() only sees the newline and stops reading. Thereafter the remaining inputs are all mismatched.
Solution: have the first scanf() (line 14) dump the newline.
Change from:
scanf("%d",&n)
To:
scanf("%d\n",&n)
And do a similar fix for reading kms in line 33.
+ 2
Ishaan Oberoi in some systems the end of line has two characters. That makes it tricky to recommend a universal solution. It might be better to replace scanf() with fgets() to retrieve the line string into a temporary char array, and then use sscanf() to read the number from the temporary string. That should handle the input consistently across platforms.
+ 1
Brian thanks I tweaked it a little and it worked
0
it's storing.
I tried this input:
1 a b c 10