ran*_*lev 0 c struct visual-studio-2015
我尝试了很多次来修复错误” Incomplete Definition of Type of struct *,请您能帮我找到问题并解决吗?
有什么建议吗?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
struct mypoint;
typedef struct mypoint {
int x;
int y;
};
void setRandomPoint(struct mypoint *a, int min, int max)
{
do {
a->x = rand();
} while (a->x > max || a->x < min);
do
{
a->y = rand();
} while (a->y > max || a->y < min);
}
int main()
{
struct myPoint point;
int min = 0, max = 0;
int i;
srand(time(NULL));
while (min >= max)
{
printf("Enter min:");
scanf("%d", &min);
printf("Enter max:");
scanf("%d", &max);
}
for (i = 0; i<5; i++)
{
setRandomPoint(&point, min, max);
printf("%d. point.x=%d, point.y=%d\n", i + 1, point.x, point.y);
}
printf("Finish.\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
请有人可以帮助我吗?
为您typedef的ed结构添加名称:
typedef struct mypoint {
int x;
int y;
} myPoint;
Run Code Online (Sandbox Code Playgroud)
从您的陈述来看:
struct myPoint point;
Run Code Online (Sandbox Code Playgroud)
我想你要给的名字是myPoint。现在,您已经忘记给它起一个名字,所以myPoint它不存在。
另请注意声明:
struct myPoint point;
Run Code Online (Sandbox Code Playgroud)
即使您为自己typedef的ed结构命名,现在使用的代码也是错误的。命名后,您可以struct使用:
myPoint point;
Run Code Online (Sandbox Code Playgroud)
要么 :
struct mypoint point;
Run Code Online (Sandbox Code Playgroud)