我想获取包含学生姓名、卷号的类(class)信息。并打印出来 我使用了结构,但代码不起作用
#include<stdio.h>
#include <string.h>
int size,i,j;
struct Student
{
char name[50];
int number;
};
typedef struct Student info1;
info1 print[100];
int main()
{
printf("Size of class : ");
scanf("%d",&size);
for(j=0;j<(20);)
{
for(i=1;i<=size;i++)
{
printf("%d.Name:",i);
scanf("%s",&info1.name);// i get an error here that an exp is expected
print[j]=info1.name; // i get an error here that an exp is expected
j++;
printf("Rollno:");
scanf("%d", &info1.number);// i get an error here that an exp is expected
print[j]=info1.number;// i get an error here that an exp is expected
}
}
for (j = 0;j <(20);)
{
printf("%s Name", print[j]);
j++;
printf("%d Rollno", print[j]);
}
return 0;
}
调试时出现以下错误:
expected exp before info1
最佳答案
在您的代码中,对于所有用法,例如
scanf("%s",&info1.name);
^^^^^
是错误的,因为 info
是数据类型的别名,而不是变量。
您已经定义了该类型的变量,print
,请使用它。
关于c - 采用不同数据类型的多个元素的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41724938/