I want to scan a file and skip a line of text before reading. I tried:
fscanf(pointer,"\n",&(*struct).test[i][j]);
But this syntax simply starts from the first line.
I was able to skip lines with scanf with the following instruction: fscanf(config_file, "%*[^\n]\n");
Using readlines() method The primary function of the readlines() method is to read a file and then return a list. Since this function returns the list, we can repeat it. If the line number you are currently on is equal to the line number you wish to skip, you remove that line. If not, you consider it.
The new line character in Python is \n . It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.
I was able to skip lines with scanf with the following instruction:
fscanf(config_file, "%*[^\n]\n");
The format string matches a line containing any character including spaces. The *
in the format string means we are not interested in saving the line, but just in incrementing the file position.
Format string explanation:%
is the character which each scanf format string starts with;*
indicates to not put the found pattern anywhere (typically you save pattern found into parameters after the format string, in this case the parameter is NULL);[^\n]
means any character except newline;\n
means newline;
so the [^\n]\n
means a full text line ending with newline.
Reference here.
fgets will get one line, and set the file pointer starting at the next line. Then, you can start reading what you wish after that first line.
char buffer[100];
fgets(buffer, 100, pointer);
It works as long as your first line is less than 100 characters long. Otherwise, you must check and loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With