当我试着编译我的c代码时,它总是告诉我;第13行:错误:应为标识符";。我的编程涉及存储数组字符串 #包括 结构名称 { 字符名称1[49]; 字符名称2[48]; 字符名称3[49]; }; 研究一、研究二、研究三; int main() { 字符名; printf(“输入第一个学生的名字”); scanf(“%s”、&struct names.name1.stud1); printf(“输入第一个学生的第二个名字\n”); scanf(“%s”、&struct names.name2.stud1); printf(“输入第一个学生的第三个名字\n”); scanf(“%s”、&struct names.name3.stud1); printf(“输入第二个学生的名字”); scanf(“%s”、&struct names.name1.stud2); printf(“输入第二个学生的第二个名字”); scanf(“%s”、&struct names.name2.stud2); printf(“输入第二个学生的第三个名字”); scanf(“%s”、&struct names.name3.stud2); printf(“输入第三个学生的名字”); scanf(“%s”、&struct names.name1.stud3); printf(“输入第三个学生的第二个名字”); scanf(“%s”、&struct names.name2.stud3); printf(“输入第三个学生的第三个名字”); scanf(“%s”、&struct names.name3.stud3); 返回0; }

当我试着编译我的c代码时,它总是告诉我;第13行:错误:应为标识符";。我的编程涉及存储数组字符串 #包括 结构名称 { 字符名称1[49]; 字符名称2[48]; 字符名称3[49]; }; 研究一、研究二、研究三; int main() { 字符名; printf(“输入第一个学生的名字”); scanf(“%s”、&struct names.name1.stud1); printf(“输入第一个学生的第二个名字\n”); scanf(“%s”、&struct names.name2.stud1); printf(“输入第一个学生的第三个名字\n”); scanf(“%s”、&struct names.name3.stud1); printf(“输入第二个学生的名字”); scanf(“%s”、&struct names.name1.stud2); printf(“输入第二个学生的第二个名字”); scanf(“%s”、&struct names.name2.stud2); printf(“输入第二个学生的第三个名字”); scanf(“%s”、&struct names.name3.stud2); printf(“输入第三个学生的名字”); scanf(“%s”、&struct names.name1.stud3); printf(“输入第三个学生的第二个名字”); scanf(“%s”、&struct names.name2.stud3); printf(“输入第三个学生的第三个名字”); scanf(“%s”、&struct names.name3.stud3); 返回0; },c,arrays,C,Arrays,您的结构定义看起来不错,但是: #include<stdio.h> struct names { char name1[49]; char name2[48]; char name3[49]; }; stud1,stud2,stud3; int main() { char names; printf("enter first name of the first student\n"); scanf("%s",&struct names.name1.st

您的结构定义看起来不错,但是:

#include<stdio.h>

struct names

{
char name1[49];

char name2[48];

char name3[49];

};

stud1,stud2,stud3;

int main()

{

char names;

printf("enter first name of the first student\n");

 scanf("%s",&struct names.name1.stud1);

printf("enter second  name of the first student\n");

scanf("%s",&struct names.name2.stud1);

printf("enter third  name of the first student\n");

scanf("%s",&struct names.name3.stud1);

printf("enter first name of the second  student\n");

scanf("%s",&struct names.name1.stud2);

printf("enter second  name of the second  student\n");

scanf("%s",&struct names.name2.stud2);

printf("enter third  name of the second  student\n");

scanf("%s",&struct names.name3.stud2);

printf("enter first name of the third  student\n");

scanf("%s",&struct names.name1.stud3);

printf("enter second  name of the third student\n");

scanf("%s",&struct names.name2.stud3);

printf("enter third  name of the third student\n");

scanf("%s",&struct names.name3.stud3);

return 0;
}
将声明三个整数变量。它不会在C99等较新标准下编译。此处需要三个类型为
struct names
的变量:

stud1,stud2,stud3;
使用变量时:

struct names stud1, stud2, stud3;
您不使用
struct names
,它是变量
stud1
的类型。它仅在对变量进行declate时使用,以便编译器知道它是什么类型。之后,使用它的名称。此外,结构变量bname在前面,字段名在后面。而且fiels
name1
是一个字符数组,所以不应该使用它的地址。最后,最好发出信号
scanf
,以免阵列溢出。因此:

scanf("%s",&struct names.name1.stud1);
请再次阅读C入门中关于类型和变量的章节

附录:可以一次性定义结构和变量,正如其他人所建议的:

scanf("%48s", &stud1.name1);
我发现这样的复合定义与其说有用,不如说更令人困惑。我建议作为初学者,应该坚持结构和变量定义的分离

在代码中删除结构体之后的seimcolon可以得到此定义,但它不会修复使用结构体的systax。

试试:

#包括


删除
struct
definition的右括号后的分号。错误不止于此。在
scanf
参数列表中使用
struct names
是不正确的。@TomKarzes是的,但不是在第13行:-)我不明白为什么大多数人发布的代码没有正确的缩进。真烦人。
struct names {
    char name1[49];
    char name2[48];
    char name3[49];
} stud1, stud2, stud3;
struct names

{
char name1[49];

char name2[48];

char name3[49];

}stud1,stud2,stud3;

int main()

{
printf("enter first name of the first student\n");

 scanf("%s",&stud1.name1);

printf("enter second  name of the first student\n");

scanf("%s",&stud1.name2);

printf("enter third  name of the first student\n");

scanf("%s",&stud1.name3);

printf("enter first name of the second  student\n");

scanf("%s",&stud1.name1);

printf("enter second  name of the second  student\n");

scanf("%s",&stud2.name2);

printf("enter third  name of the second  student\n");

scanf("%s",&stud2.name3);

printf("enter first name of the third  student\n");

scanf("%s",&stud3.name1);

printf("enter second  name of the third student\n");

scanf("%s",&stud3.name2);

printf("enter third  name of the third student\n");

scanf("%s",&stud3.name3);

return 0;
}