[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

identifiers

Posted on 1999-12-14
7
Medium Priority
?
290 Views
Last Modified: 2010-04-15
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'
0
Comment
Question by:cbrookhart
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2282112
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
 

Author Comment

by:cbrookhart
ID: 2282123
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
 
LVL 86

Expert Comment

by:jkr
ID: 2282133
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
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

 
LVL 86

Expert Comment

by:jkr
ID: 2282138
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
 

Author Comment

by:cbrookhart
ID: 2282259
Thanks for your help. The program seems to be working now.
0
 
LVL 86

Expert Comment

by:jkr
ID: 2284103
Fine!

Hmm, so you should grade the question in order to move it to the PAQ section...
0
 

Author Comment

by:cbrookhart
ID: 2285440
I thought I had clicked the grade button when I posted the comment.
0

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question