Good afternoon,
I am trying to write a module to read an unknown, albeit very small (10-15), number of parameters from a text file( such as "Width: 200\n" ). However, I want to be able to specify the parameters in any order and omit some if necessary.
I figured I should loop through all the lines using fscanf, continuously checking the return value after each iteration and acting appropriately. (i.e if the parameter is read, exit the loop and carry on to the next parameter, otherwise if we hit the EOF marker and the value was not found, assign it a
default value)
However, this approach doesn't work for some reason.Code:width = -1; // assign a dummy value while ( (fc = fscanf(filePtr, "Width:%d\n", &width)) != EOF ) { if( fc == 1) break; // parameter was read so exit the loop } if( width == -1 ) width = 300; // parameter not found so default it
Any help would be appreciated.
Duetti



LinkBack URL
About LinkBacks


