Conditionally skipping entire line with just fscanf
How can this be done with just
fscanf
?
fscanf(stdin, "%*[^\n]");
will read all characters other than a new-line character, until an error or end-of-file occurs.
*
says to suppress assignment of the data being read.
By default, [
starts a list of characters to accept. However, ^
negates that; [^\n]
says to accept all characters other than a new-line character.