Here's a super-basic C question (this seemed like the most apt place to ask, sorry if there's a better spot). I've got this code, which is derived largely from the fscanf reference at cplusplus.com. All it does is read a file called coords.txt, which should contain a listing of coordinate pairs. Then it just says how many are there.

Code:
/* fscanf example */
#include <stdio.h>

int main ()
{
  float xtemp, ytemp;
  FILE *pFile;
  int n;

  // Open the file with the coordinates and check that it opened OK.
  pFile = fopen("coords.txt","r");
  if(pFile == NULL)
  {
    printf("The file coords.txt does not exist.\n");
    printf("Please create this file before running the program again.\n");

    return 1;
  }

  // Now read formatted pairs until you hit the end of file
  n = 0;
  while(fscanf(pFile, "%f %f", &xtemp, &ytemp) != EOF)
  {
    n++;
    printf("Line %i \n", n);
  }

  printf("There are %i coordinate pairs.\n", n);

  return 0;
}
So, if you give it a coords.txt file that looks like this:
Code:
4.234 -23.43
0.111 0.222
-3 4
Everything's fine. The output is as expected, and the program exits normally:

Code:
Line 1 
Line 2 
Line 3 
There are 3 coordinate pairs.
Now, if I remember correctly, in Fortran, you can read from a file in a similar way, and it doesn't care if the values are separated by a newline, a space, multiple spaces, a tab, or a comma. So, if you add a comma to coords.txt so it reads

Code:
4.234 -23.43
0.111 0.222
-3, 4
Now the program freaks out when you run it. It never stops, it just keeps outputting:

Code:
Line 1 
Line 2 
Line 3 
Line 4
Line 5
and so on until you kill it.

So obviously this doesn't work like Fortran. I understand that, but I have a couple questions. First, my only explanation is that if fscanf fails to read properly formatted data, it never proceeds further through the file, and thus never hits the EOF. Is that correct? If not, why else would this happen? Beyond that, is there a simple way to make it tolerate comma-separation in the data file? It's not critical to what I'm doing, but I like to know these things.

I'm trying to keep the code as simple as possible, so I didn't want to use filestreams or anything. I'd like to stick to the most basic functions here... This isn't meant to be great code, it's intended for learning this stuff.

Thanks!