2 things to say:
- It looks nicer when you use one format string
- You should use a loop
Here's some code:
int a,b,c;
char str[256];
while(fscanf(fd, "%d %d %d %s ", &a, &b, &c, &str[0]str) == 4){
//get some coffee
}
this is a standard while not End of File loop. Also, str
doesn't need &
because it already is a pointer and doesn't need to be referenced like a
, b
or c
. The space at the end of the format string, after %s
, means it will stop once that one space is read. This way it is not included in the string str
.