How to resolve “parameter has incomplete type” error?

后端 未结 2 1243
后悔当初
后悔当初 2021-01-29 09:47

I\'m a newbie and I need help with debugging my code. When I compile it \'type of formal parameter 1 is incomplete\' and type of formal parameter 2 is incomplete\' error appears

2条回答
  •  甜味超标
    2021-01-29 10:02

    Your program is showing incomplete type error because the scope of struct date is limited to main() function only. Outside the main() the structure definition is not visible.

    So, the struct date definition should be in global scope so that it is visible from calc_age() (and maybe other functions, too). Even better, if you can create and maintain a header file for this purpose.

    That said, in your code, as per your current requirement, get rid of single-element arrays in the structure, like

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

    and also, the scanf() statement

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

    should read

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

提交回复
热议问题