#include<stdio.h>
#include<string.h>
#define MAX 50
struct student
{
int srn;
char stu_name[30];
char course[18];
char addr[50];
};
int main()
{
struct student st[MAX];
int i;
for (i = 0; i < MAX; i++)
{
printf("\nEnter name of the student %d : ", st[i].srn=i+1);
scanf("%s", st[i].stu_name);
printf("\nEnter course of the student %d : ", i+1);
scanf("%s", st[i].course);
printf("\nEnter address of the student %d : ", i+1);
scanf("%s", st[i].addr);
}
for (i = 0; i < MAX; i++)
{
printf("\nname of student %d is %s", i+1, st[i].stu_name);
printf("\ncourse is %s", st[i].course);
printf("\naddr is %s", st[i].addr);
}
return 0;
}
我为一个学校项目写了这段代码,但代码块一直给我这个error.Anyone,知道解决方案吗?main.c|21|error: '(struct student *)&st' is a pointer; did you mean to use '->'?|
发布于 2020-12-13 13:48:25
不能在打印的同一行中赋值,这就是整个问题所在
试着这样做可能会有用
st[i+1].srn
而不是
st[i].srn=i+1
结束代码应该如下所示
int main()
{
struct student st[MAX];
int i;
for (i = 0; i < MAX; i++)
{
st[i].srn = i+1;
printf("\nEnter name of the student %d : ", st[i].srn);
scanf("%s", st[i].stu_name);
printf("\nEnter course of the student %d : ", i+1);
scanf("%s", st[i].course);
printf("\nEnter address of the student %d : ", i+1);
scanf("%s", st[i].addr);
}
for (i = 0; i < MAX; i++)
{
printf("\nname of student %d is %s", i+1, st[i].stu_name);
printf("\nname of student %d is %s", st[i].srn, st[i].stu_name);
printf("\ncourse is %s", st[i].course);
printf("\naddr is %s", st[i].addr);
}
return 0;
}
https://stackoverflow.com/questions/65272666
复制相似问题