It is one way to count several instances of repeating character. Since we are always keeping track of the previous character and the current character, then if both prev and current are '\n', we have 2 newlines in a row.
Another method could be
Code:
int skip_record(int cch)
{
int occurrences = 0; /* occurrences of '\n' in input */
while ( (cch!= EOF) && (occurrences < 2) )
{
if (cch == '\n')
occurrences++;
else
occurrences = 0;
cch = getchar();
}
while (cch=='\n') cch = getchar();
return cch;
}
Now if 2 occurrences of '\n' appear one after the other, occurrences will be incremented twice and the while loop will terminate because occurrences is no longer less than 2, but if something else comes through between the two '\n' characters then occurrences will reset to 0.
This version of the function is almost identical, just a different way of counting 2 concurrent newline characters from input. One advantage this would have is that you could more easily change what character you are counting, or you could wait for more than just 2 in a row. However this is probably getting away from the intent of this particular function and is really academic since we still have no idea what the context of this single function is.