I'm trying to validate lines in a file with actual content in them, and exiting on cases where there are two empty lines in a row. Can this be done? This code results in fgetc() not catching the double carriage returns/new lines.
Code is a snippet from a C89 project, so declarations are made above snippet.
if ((file = fopen(fileName,"r")) == NULL)
{
free(fileName);
exit(1);
}
while (c != EOF)
{
cOld = c;
c = fgetc(file);
/* count lines */
if(c == '\n'){
newLine++;
}
/* test for two carriage returns in a row */
if(c == '\n' && cOld == '\n'){
printf("ERROR: Invalid File\n");
free(fileName);
exit(1);
}
}