I just learned about c structures the other day but I can't seem to get them to work. It give the wrong result at the end.
The warnings I'm getting are:
In function `main':
24 [Warning] comparison between pointer and integer
26 [Warning] assignment makes integer from pointer without a cast
27 [Warning] passing arg 1 of `strcpy' from incompatible pointer type
29 assignment makes integer from pointer without a cast
Code:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
struct student
{
char name [50];
char id [50];
char score [50];
};
int main ()
{
int i;
char sum=0, high=0,avg, highest[50][50];
struct student stu[i];
for (i=0; i<=4; i++)
{
printf ("Enter the student's name.");
scanf ("%s", &stu[i].name);
printf ("Enter the student's ID.");
scanf ("%s", &stu[i].id);
printf ("Enter the student's score.");
scanf ("%f", &stu[i].score);
if (stu[i].score>high)
{
high = stu[i].score;
strcpy (highest,stu[i].name);
}
sum = sum + stu[i].score;
}
avg = sum/5;
printf ("Student %s got the highest grade of %f", highest, high);
system ("pause");
return 0;
}