Since you're not consuming the whole line with your fscanf
, the remaining values trip up your scan. Either use fgets
to read the whole line and then scan if with sscanf
, or add %*[^\n]
to the end of your fscanf
(which reads characters until it encounters a newline character, and due to the asterisk, ignores those characters).
Also, you should test fscanf
's return value against the number of expected fields, which in your case is 4.
while (fscanf(fp,"%d (%f ,%f) %d%*[^\n]", &n.id, &n.h, &n.w, &n.pc) == 4)
printf("%d (%f ,%f) %d\n", n.id, n.h, n.w, n.pc);