I am trying to parse a text file (CSS) using fscanf and pull out all the statements matching this pattern:
@import "some / file / something.css";
To do this, I have the following loop installed:
FILE *file = fopen(pathToSomeFile, "r");
char *buffer = (char *)malloc(sizeof(char) * 9000);
while(!feof(file))
{
if(fscanf(file, "%*[^@] %8999[^;]", buffer) == 1)
{
}
}
This works fine for as long as the VERY FIRST character in the file is not "@". (Literally, one space before the first "@" in the CSS file will make the code run.)
But if the very first character in the CSS file is “@”, then what I see in the debugger is an infinite loop - execution enters the while loop, gets into the fscanf statement, but doesn't enter the “if '(fscanf doesn't work), and then continues through the cycle forever.
, fscanf formatters , , . , ?
.