First, this line
fscanf(finput, "%s, %d, %d", x, y, z)
should be fixed to eliminate undefined behavior:
fscanf(finput, "%s, %d, %d", x, &y, &z)
// ^ ^
// | |
// You need to take an address of int variables
If you do not want the comma to be included in your string, use %[^,]
instead:
fscanf(finput, "%5[^,], %d, %d", x, &y, &z)
// ^^^^
// ||
// This means "read characters until you hit a comma
Note that I added 5
to limit the length of the string being read to six char
s.
Finally, to see if the fscanf
returned a proper number of items, get its return value, and check if it's equal to the number of items that you expected:
int count = fscanf(finput, "%5[^,], %d, %d", x, &y, &z);
if (count == 3) {
// All three items are there
} else {
// We did not get enough items
}