#include <stdio.h>
#include <string.h>
typedef struct Student
{
int GL;
char FN[80];
char LN[80];
double GPA;
}SArray[956];
int main(void)
{
int OP = 0;
int i;
int x = 0;
struct Student SArray[956];
while(x == 0)
{
printf("Welcome to teh ARX7 SYSTEM. Enter 1 to enter information, 2.............\n");
scanf("%d", &OP);
if (OP == 1)
{
printf("Enter Student ID:\n");
scanf("%d", &i);
printf("Enter Grade Level:\n");
scanf("%d",&SArray[i].GL);
printf("Enter First Name:\n");
gets("%s",&SArray[i].FN);
printf("Enter Last Name:\n");
gets("%s",&SArray[i].LN);
printf("Enter GPA:\n");
scanf("%lf", &SArray[i].GPA);
}
if (OP == 2)
{
printf("Enter Student ID:\n");
scanf("%d", &i);
printf("Grade: %d",&SArray[i].GL);
printf("First name: %s\n", SArray[i].FN);
printf("Last name: %s\n", SArray[i].LN );
printf("GPA: %lf ", &SArray[i].GPA);
}
}
}
I'm trying to create a program that stores and displays data for students. However, I keep getting these two errors:
main.c:71:23: warning: format specifies type 'int' but the argument has type 'int *' [-Wformat]
printf("Grade: %d",&SArray[i].GL);
main.c:74:24: warning: format specifies type 'double' but the argument has type 'double *' [-Wformat]
printf("GPA: %lf ", &SArray[i].GPA);
INPUT:
Welcome to teh ARX7 SYSTEM. Enter 1 to enter information, 2.............
1
Enter Student ID:
1
Enter Grade Level:
2
Enter First Name:
ee
Enter Last Name:
eee
Enter GPA:
3
OUPUT:
Welcome to teh ARX7 SYSTEM. Enter 1 to enter information, 2.............
2
Enter Student ID:
1
Grade: -1264132192
First name: ee
Last name: eee
GPA: 0.000000
scanfneeds a pointer to the object, so that it can store a value in the object.printfjust needs the value of the object. Soscanfneeds&i(the address ofi) whereasprintfjust needsi(the value ofi). Also,getsis evil and should not be used. Usefgetsinstead. And consult the documentation, since you weren't callinggetscorrectly anyways.gets? Please add the updated code to the question.