#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);
}
}
}
我正在尝试创建一个存储和显示学生数据的程序。但是,我一直收到这两个错误:
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
答案 0 :(得分:2)
取出&#39;&amp;&#39;在第71行和第74行中。您为printf函数提供了一个指向所需值的指针 - 它的地址 - 而不是值本身。
答案 1 :(得分:0)
struct
名为SArray[956]
的数组,一次是全球性的,一次是本地一次,不要这样做,使用{时不需要struct
个关键字{1}}喜欢这个。typedef
用于&
和FN
。LN
将变量传递给&
printf
不需要格式说明符,例如gets
。 (%s
已被停用,您应该更喜欢使用gets
,请参阅here。)fgets
之前getchar()
要忽略流中的额外gets
,因为上一个\n
。只是做出这些改变:
scanf