如何解决“参数有不完整类型”的错误?

我是新手,我需要帮助调试我的代码。 当我编译它”forms参数1的类型不完整’和forms参数2的类型是不完整的’错误出现在

printf("Age is %d years.\n", calc_age(birth, current)); 

而’参数1(’出生’)具有不完整类型’和’参数2(’当前’)具有不完整类型’错误出现在

 int calc_age (struct date birth, struct date current) { 

感谢帮助,谢谢!

 #include  int calc_age (struct date birth, struct date current); int main(void) { struct date { int month[1]; int day[1]; int year[1]; }; struct date birth, current; char c; printf("Input the birthdate (MM/DD/YY): "); scanf("%d %c %d %c %d", birth.month, &c, birth.day, &c, birth.year); printf("Input date to calculate (MM/DD/YY): "); scanf("%d %c %d %c %d", current.month, &c, current.day, &c, current.year); printf("Age is %d years.\n", calc_age(birth, current)); return 0; } int calc_age (struct date birth, struct date current) { int age; if (birth.month[0]  current.month[0]) { age = (current.year[0] - birth.year[0] - 1); } else { if (birth.day[0] <= current.day[0]) { age = (current.year[0] - birth.year[0]); } else { age = (current.year[0] - birth.year[0] - 1); } } return age; } 

 #include  struct date { int month[1]; int day[1]; int year[1]; }; int calc_age (struct date birth, struct date current); int main(void) { struct date birth, current; char c; printf("Input the birthdate (MM/DD/YY): "); scanf("%d %c %d %c %d", birth.month, &c, birth.day, &c, birth.year); printf("Input date to calculate (MM/DD/YY): "); scanf("%d %c %d %c %d", current.month, &c, current.day, &c, current.year); printf("Age is %d years.\n", calc_age(birth, current)); return 0; } int calc_age (struct date birth, struct date current) { int age; if (birth.month[0] < current.month[0]) { age = (current.year[0] - birth.year[0]); } else if (birth.month[0] > current.month[0]) { age = (current.year[0] - birth.year[0] - 1); } else { if (birth.day[0] <= current.day[0]) { age = (current.year[0] - birth.year[0]); } else { age = (current.year[0] - birth.year[0] - 1); } } return age; } 

您应该在main之前定义结构

您的程序显示incomplete type错误,因为struct date的范围仅限于main()函数。 在main() ,结构定义不可见。

因此, struct date定义应该在全局范围内,以便从calc_age() (也可能是其他函数calc_age()可见。 更好的是,如果您可以为此目的创建和维护头文件。

也就是说,在您的代码中,根据您当前的要求,摆脱结构中的单元素数组,例如

 struct date { int month; int day; int year; }; 

还有, scanf()语句

 scanf("%d %c %d %c %d", birth.month, &c, birth.day, &c, birth.year); 

应该读

 scanf("%d %c %d %c %d", &birth.month, &c, &birth.day, &c, &birth.year);