【发布时间】:2014-02-20 11:50:02
【问题描述】:
我有一个 C 程序,我试图用 scanf 设置 struct 值。我收到一个错误:
s.c: In function ‘main’:
s.c:15:17: error: expected expression before ‘ROBOT’
从此代码:
enum DIRECTION {N,E,S,W};
typedef struct {
int xpos;
int ypos;
enum DIRECTION dir;
} ROBOT;
int main() {
int x, y, i;
char string[20];
printf("Enter x coordinate: \n");
scanf("%i", &ROBOT.xpos);
}
这个错误是什么意思,我做错了什么?
【问题讨论】:
-
&ROBOT.xpos,ROBOT是什么?你需要在某个地方有ROBOT robot;。 -
下次请发布错误,以便用户轻松识别问题。
-
写
scanf("%i", &ROBOT.xpos);就像写scanf("%i", &int);