can fscanf skip reading data conditionally?
- From: "John" <javacc1@xxxxxxxxx>
- Date: 27 Sep 2006 08:54:47 -0700
I need to read data from the file like the following with name and
score, but some line may only has name without score:
joe 100
amy 80
may
Here's my code, but it couldn't read the line with "may" because there
is no score. Anyone knows what is the workaround to this problem?
char name[20];
int score;
while (fscanf(ifp, "%s %d", name, &score) == 2)
{
printf("%s %d\n", name, score);
}
please advice. thanks!!
.
- Follow-Ups:
- Re: can fscanf skip reading data conditionally?
- From: Michael Mair
- Re: can fscanf skip reading data conditionally?
- From: Robert Gamble
- Re: can fscanf skip reading data conditionally?
- From: Fred Kleinschmidt
- Re: can fscanf skip reading data conditionally?
- Prev by Date: Re: C99 Versus ANSI.
- Next by Date: Re: what is graph & use in the general life?
- Previous by thread: C exercises?
- Next by thread: Re: can fscanf skip reading data conditionally?
- Index(es):
Relevant Pages
|