Searching for values

I am trying to get a particular value from this program and match that value with a name. It seems that I have done something wrong, since the program doesn't compile. Do I need to create another set of '{' for the subscripts? Am I going about getting this value the wrong way? The value is actually a salary and the highest salary along with the name should be printed. This program was working fine before I added the subscript statements.

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char player[9];
int jersey;
long int salary;
char sport[12];
int hisub=0;
int sub=0;
FILE * infile;
infile = fopen("a:\\sports.dat","r");
for (sub=0; sub<9; sub++);
printf("Player Name    Salary      Jersey        Sport\n");
while (fscanf(infile, "%s%d%d%s",player,&jersey,&salary,&sport)!=EOF)
if (salary[sub]>salary[hisub])
hisub=sub;
{
printf("%s           %3d       %4d      %5s\n",player,salary,jersey,sport);
printf("%s has the highest salary of %d\n",player[hisub],salary[hisub]);
}
fclose(infile);
return 0;
}

A:\sports.c(21) : error C2109: subscript requires array or pointer type
A:\sports.c(21) : error C2109: subscript requires array or pointer type
A:\sports.c(25) : error C2109: subscript requires array or pointer type
cbrookhartAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
deightonConnect With a Mentor Commented:
#include <string.h>
0
 
ozoCommented:
What do salary[sub] and salary[hisub] mean?
You've declared salary as a long int, not an array.
0
 
zultiCommented:
maybe that what you wanted
pay attention for the slight changes.



#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   char player[9],hiplayer[9];
   int jersey;
   long int salary, hisalary;
   char sport[12];
   FILE * infile;
   infile = fopen("a:\\sports.dat","r");
   if (! infile)
      return -1 ;
   printf("Player Name    Salary      Jersey        Sport\n");
   while (fscanf(infile, "%s%d%d%s",player,&jersey,&salary,&sport)!=EOF)
   {
      if (salary>hisalary)
      {
         hisalary=salary ;
         strcpy(hiplayer,player) ;
      }
      printf("%s           %3d       %4d      %5s\n",player,salary,jersey,sport);
   }
   printf("%s has the highest salary of %d\n",hiplayer,hisalary);
   fclose(infile);
   return 0;
}
0
 
cbrookhartAuthor Commented:
strcpy is undefined.

A:\sports.c(24) : warning C4013: 'strcpy' undefined; assuming extern returning int

Is there something in the wrong place?
0
 
cbrookhartAuthor Commented:
I realized after posting the above message that I forgot to put in the string header file.

Thanks for the help.
0
All Courses

From novice to tech pro — start learning today.