best way to read a string
ok before you jump to give me a link to the faq's, check this out...
Reading a string from a file, have to stop when i get to a certain delimiter, can contain white space in string. What I have is this....
Code:
int ch;
int index = 0;
while (( ch = fgetc( fp )) != delimeter && ch != '\n' && ch != EOF ) {
*(buffer + index) = (char)ch;
index++;
if ( index == max_buffer ) {
break;
}
}
What i want is to do it with fscanf but i cant work out how to get it to keep reading past the whitespace and stop at the delimiter.
Code:
???? fscanf( fp, "%s,", string ); //doesnt skip white space
Any help would be great.
Edit: fixed up code sample