I'm using an ANSI C program to read in data from a file that has, every few lines, a name on it. Sometimes the name is just a first name, as in "Dave", and sometimes it's two names, as in "Bob Jones". I need to store the name in a string, and I need all of it (not just the first name when two names are present).
I took a hint from another DevShed Forum discussion and tried this for the line that reads in the name:
The idea is that the "%[^\n]" gets everything but newlines, so I get everything on the present line in the file buffer (ipf). But when I do this repeatedly with other names or multi-word values I get nothing. I've gone in with a debugger, and after those lines (that are, practically, identical to the above with the substitution of a different string the fscanf()'d data is being stored in) nothing is stored in them. It's like those subsequent fscanf()'s are reading in null terminators (\0's) from the file.Code:fscanf( ipf, "%[^\n]", struct.memberString );
Basically, my question is this: how the heck in ANSI C do I read in just a line from a file buffer, getting everything on the line including spaces but not newlines and stray null terminators? Is my fscanf() syntax wrong? Should I be using fgetc() and some sort of while loop? Please help!