Hello Guys
I get the following error when I use the Unix cc compiler
------------------------------
cc-1164 cc: WARNING File = struct.c, Line = 39
Argument of type "struct Student (*)[5]" is incompatible with parameter of
type "struct Student *".
FindMax(&list, 5);
------------------------------
and I get the following errors if I use gcc or VC++ compilers.
------------------------------
warning C4047: 'function' : 'struct Student *' differs in levels of indirection from 'struct Student (*)[5]'
warning C4024: 'FindMax' : different types for formal and actual parameter 1
------------------------------
Can anybody tell me how can I fix them? My program is listed below.
/* Struct Assignment */
#include <stdio.h>
int i;
struct Student
{
int Score;
char Name[10];
};
void FindMax(struct Student *myStruct, int index);
void main()
{
struct Student list[5] =
{
{90,"Mike"},
{50,"Don"},
{89,"Tom"},
{70,"Jeff"},
{100,"Ron"}
};
printf("Name\t\tScore\n"
printf("----\t\t-----\n"
for (i = 0; i < 5; i++)
{
printf("%s", list.Name);
printf("\t\t%d\n", list.Score);
}
FindMax(&list, 5);
}
void FindMax(struct Student *myStruct, int index)
{
int HighScore, i;
int HighStudent;
HighScore=0;
for (i=0; i<index; i++)
{
if (((myStruct+i)->Score) > HighScore)
{
HighScore = (myStruct+i)->Score;
HighStudent = i;
}
}
printf("The Student that has the highest score is: "
printf("%s \n", (myStruct+HighStudent)->Name);
printf("The highest score is: %d \n",HighScore);
}
I get the following error when I use the Unix cc compiler
------------------------------
cc-1164 cc: WARNING File = struct.c, Line = 39
Argument of type "struct Student (*)[5]" is incompatible with parameter of
type "struct Student *".
FindMax(&list, 5);
------------------------------
and I get the following errors if I use gcc or VC++ compilers.
------------------------------
warning C4047: 'function' : 'struct Student *' differs in levels of indirection from 'struct Student (*)[5]'
warning C4024: 'FindMax' : different types for formal and actual parameter 1
------------------------------
Can anybody tell me how can I fix them? My program is listed below.
/* Struct Assignment */
#include <stdio.h>
int i;
struct Student
{
int Score;
char Name[10];
};
void FindMax(struct Student *myStruct, int index);
void main()
{
struct Student list[5] =
{
{90,"Mike"},
{50,"Don"},
{89,"Tom"},
{70,"Jeff"},
{100,"Ron"}
};
printf("Name\t\tScore\n"
printf("----\t\t-----\n"
for (i = 0; i < 5; i++)
{
printf("%s", list.Name);
printf("\t\t%d\n", list.Score);
}
FindMax(&list, 5);
}
void FindMax(struct Student *myStruct, int index)
{
int HighScore, i;
int HighStudent;
HighScore=0;
for (i=0; i<index; i++)
{
if (((myStruct+i)->Score) > HighScore)
{
HighScore = (myStruct+i)->Score;
HighStudent = i;
}
}
printf("The Student that has the highest score is: "
printf("%s \n", (myStruct+HighStudent)->Name);
printf("The highest score is: %d \n",HighScore);
}