C 错误:在‘之前应为表达式;st’;
我在用C语言尝试这个简单的结构程序,但在编译时,我在3个地方(第17、20和22行)出现了以下错误。我检查了密码,但没有找到错误。我哪里做错了 注意:如果将结构声明和typedef语句放在main()函数中,则会出现相同的错误C 错误:在‘之前应为表达式;st’;,c,struct,C,Struct,我在用C语言尝试这个简单的结构程序,但在编译时,我在3个地方(第17、20和22行)出现了以下错误。我检查了密码,但没有找到错误。我哪里做错了 注意:如果将结构声明和typedef语句放在main()函数中,则会出现相同的错误 #include <stdio.h> #include <stdlib.h> struct my_struct { int a; int b; }; typedef struct my_struct st; void main
#include <stdio.h>
#include <stdlib.h>
struct my_struct
{
int a;
int b;
};
typedef struct my_struct st;
void main()
{
printf("Enterting values into the structure.\n");
printf("Enter value of a:\n");
scanf("%d",&st.a);
printf("Enter value of b:\n");
scanf("%d",&st.b);
printf("Values of a is: %d.\nValue of b is: %d.\n",st.a,st.b);
}
#包括
#包括
结构我的结构
{
INTA;
int b;
};
typedef struct my_struct st;
void main()
{
printf(“在结构中输入值。\n”);
printf(“输入a:\n的值”);
scanf(“%d”和st.a”);
printf(“输入b:\n的值”);
scanf(“%d”和st.b);
printf(“a的值为:%d.\n b的值为:%d.\n”,st.a,st.b);
}
st
是对象的类型,如int
、char
等。它不是变量的名称
试试这个:
#include <stdio.h>
#include <stdlib.h>
struct my_struct
{
int a;
int b;
};
typedef struct my_struct st;
int main()
{
st str;
printf("Enterting values into the structure.\n");
printf("Enter value of a:\n");
scanf("%d",&str.a);
printf("Enter value of b:\n");
scanf("%d",&str.b);
printf("Values of a is: %d.\nValue of b is: %d.\n",str.a,str.b);
}
#包括
#包括
结构我的结构
{
INTA;
int b;
};
typedef struct my_struct st;
int main()
{
st-str;
printf(“在结构中输入值。\n”);
printf(“输入a:\n的值”);
scanf(“%d”和str.a);
printf(“输入b:\n的值”);
scanf(“%d”和str.b);
printf(“a的值为:%d.\n b的值为:%d.\n”,str.a,str.b);
}
st
是对象的类型,如int
、char
等。它不是变量的名称
试试这个:
#include <stdio.h>
#include <stdlib.h>
struct my_struct
{
int a;
int b;
};
typedef struct my_struct st;
int main()
{
st str;
printf("Enterting values into the structure.\n");
printf("Enter value of a:\n");
scanf("%d",&str.a);
printf("Enter value of b:\n");
scanf("%d",&str.b);
printf("Values of a is: %d.\nValue of b is: %d.\n",str.a,str.b);
}
#包括
#包括
结构我的结构
{
INTA;
int b;
};
typedef struct my_struct st;
int main()
{
st-str;
printf(“在结构中输入值。\n”);
printf(“输入a:\n的值”);
scanf(“%d”和str.a);
printf(“输入b:\n的值”);
scanf(“%d”和str.b);
printf(“a的值为:%d.\n b的值为:%d.\n”,str.a,str.b);
}
st
是一种对象类型。在main中
声明一个结构变量-
st st1;
然后使用它访问成员
void main()
->int main(void)
或int main(int argc,char**argv)
st
是一种对象类型。在main中
声明一个结构变量-
st st1;
然后使用它访问成员
void main()
->int main(void)
或int main(int argc,char**argv)
您定义了结构和类型定义
但您从未声明过结构的实例
建议删除“typedef”一词
然后修复main()函数声明您定义了一个struct和一个typedef 但您从未声明过结构的实例 建议删除“typedef”一词
然后修复main()函数声明main()函数的返回类型始终为“int”。你的编译器应该告诉你的。始终修复编译器告诉您的问题。main()函数的返回类型始终为“int”。你的编译器应该告诉你的。始终修复编译器告诉您的问题。此答案有一个
void main()
,它不是main始终返回的有效语句int@user3629249谢谢您的更正;)我向某人解释了为什么不使用void main()
,最后我把它作为一个答案。这个答案有一个void main()
,它不是一个有效的语句,因为main总是返回int@user3629249谢谢您的更正;)当时我正在向某人解释为什么不能void main()
,最后我把它作为一个答案。