Such a reading problem is usually caused by the fact that after a formatted reading, for example, a line is read. Characters not included in the format data (usually a newline character) remain in the input buffer and are read as a [blank] line on the next reading.
Here’s what a wrong C code might look like:
fscanf(file,"%d",&intVar); fgets(buf,buflen,file);
(by itself, the same applies to keyboard input - type scanf("%d",&intVar) ).
Or in C ++:
inputStream >> intVar; inputStream.getline(buf,buflen);
There may be other options.
Treatment (if you do not change the logic and reading functions, which, of course, is also possible) consists in resetting the input buffer - ignoring all characters to the end of the line between the formatted input and the next line.
In C ++, this can be done with the following code (which means to ignore all characters up to '\n' including '\n' ):
inputStream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
In C, you can explicitly read and ignore all characters to the end of the line:
while(fgetc(file) != '\n');
(Of course, it makes sense to also check for a read error - that the character read is not equal to EOF . When reading from the keyboard, you can simply use stdin instead of file , you can - getchar() .)
Another option in C -
fscanf(file,"%*[^\n]"); fscanf(file,"%*c");