How to read a file until a character in C
So I have this input file:
1 2 3 4 5 6 7
3 2 4 1 6 5 7
***
1 1 2
1 1 2
***end of input***
I want to scan the first two lines of integers, then something with them,
then skip the * and scan the next lines of integers, and do something with
them as well (like a loop until it reads *).
How could I do that? Here's my code:
int main(){
int i = 0, j ;
int temp[100];
char c, buf[20];
FILE *fp;
fp = fopen("input.txt", "r");
if (fp != NULL){
while (1 == fscanf(fp, "%d ", &temp[i])){
i++;
}
// do something with the integers
}
else{
printf("Cannot open File!\n");
}
return 0;
}
So the problem is, I can only scan the first two lines of integers. I want
to scan the integers after the * as well.
No comments:
Post a Comment