• C

identifiers

I have created this program and have compiled it. There seems to be a problem with the identifier I have used, fscanf. What did I do wrong?

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char player[12];
int jersey;
long int salary;
FILE * infile;
infile = fopen("a:\\sports.dat","r");
while fscanf(infile, "%s%d%d",player,&jersey,&salary)!=EOF)
fscanf(infile "%s%d%d",player,&jersey,&salary);
printf("%s %d %d\n",player,jersey,salary);
fclose(infile);
return 0;
}

A:\sports.c(10) : error C2061: syntax error : identifier 'fscanf'
cbrookhartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Change

while fscanf(infile, "%s%d%d",player,&jersey,&salary)!=EOF)

 to read

while (fscanf(infile, "%s%d%d",player,&jersey,&salary)!=EOF)

You forgot to open the bracket for the 'while()' condition...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbrookhartAuthor Commented:
Changing the while condition resulted in:

A:\sports.c(11) : error C2143: syntax error : missing ')' before 'string'
A:\sports.c(11) : error C2198: 'fscanf' : too few actual parameters
A:\sports.c(11) : error C2059: syntax error : ')'
0
jkrCommented:
Ooop, I've overseen something - the whole compound ('{}') is missing, the code should read:

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char player[12];
int jersey;
long int salary;
FILE * infile;
infile = fopen("a:\\sports.dat","r");
while (fscanf(infile, "%s%d%d",player,&jersey,&salary)!=EOF)
{
fscanf(infile "%s%d%d",player,&jersey,&salary);
printf("%s %d %d\n",player,jersey,salary);
}
fclose(infile);
return 0;
}
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jkrCommented:
Hate to correct myself, but

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char player[12];
int jersey;
long int salary;
FILE * infile;
infile = fopen("a:\\sports.dat","r");
while (fscanf(infile, "%s%d%d",player,&jersey,&salary)!=EOF)
{
printf("%s %d %d\n",player,jersey,salary);
}
fclose(infile);
return 0;
}

will lead to the desired results - the 'fscanf()' inside the lop is not needed...
0
cbrookhartAuthor Commented:
Thanks for your help. The program seems to be working now.
0
jkrCommented:
Fine!

Hmm, so you should grade the question in order to move it to the PAQ section...
0
cbrookhartAuthor Commented:
I thought I had clicked the grade button when I posted the comment.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.