C 语言错误: "unknown type name 'Robot'; use 'struct' keyword to refer to the type"
The error message indicates that there is an issue with the code in the main function. It seems that the type Robot is not recognized.
To fix this issue, you need to define the struct keyword before using the Robot type. Here's an example of how to do it:
\
#include <stdio.h>\
\
typedef struct {\
int blood;\
int x;\
int y;\
} Robot;\
\
int main() {\
Robot *robot;\
robot->blood = 100;\
robot->x = 0;\
robot->y = 0;\
\
printf("Robot's blood: %d\n", robot->blood);\
printf("Robot's x coordinate: %d\n", robot->x);\
printf("Robot's y coordinate: %d\n", robot->y);\
\
return 0;\
}\
```\
\
This code defines a `Robot` structure with `blood`, `x`, and `y` as its members. In the `main` function, a pointer to `robot` is declared and the members are accessed using the `->` operator. Finally, the values of the members are printed using `printf`.
原文地址: https://www.cveoy.top/t/topic/pxdo 著作权归作者所有。请勿转载和采集!