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 errors 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; }
Line 24: you are attempting to compare a pointer to the first element of a char score[50] with a char high.
The other errors (I didn't check all of them) appear to be related. Why isn't score, high, sum, and avg an int?
Thanks for replying but I figured out the problem
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks