如何解决"参数具有不完整的类型"错误? [英] How to resolve "parameter has incomplete type" error?

查看:1116
本文介绍了如何解决"参数具有不完整的类型"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手,我需要调试我的code帮助。
当我编译它的类型形式参数1不完整和形式参数2类型是不完整的中出现错误

 的printf(年龄为%d年\\ n,calc_age(出生,电流));

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

  INT calc_age(结构出生日期,结构日期电流){

帮助是AP preciated,谢谢!

 的#include<&stdio.h中GT;
INT calc_age(结构出生日期,结构日期电流);
INT主要(无效)
{    结构日期{
        月整型[1];
        日整型[1];
        年整型[1];};
    结构出生日期,电流;
    焦炭℃;    的printf(输入出生日期(MM / DD / YY):);
    scanf函数(%D%C%D%C%D,birth.month,和C,birth.day,和C,birth.year);
    的printf(输入日期计算(MM / DD / YY):);
    scanf函数(%D%C%D%C%D,current.month,和C,current.day,和C,current.year);    的printf(年龄为%d年\\ n,calc_age(出生,电流));    返回0;}INT calc_age(结构出生日期,结构日期电流){    INT年龄;    如果(birth.month [0]&下; current.month [0]){
        年龄=(current.year [0] - birth.year [0]);
    }否则如果(birth.month [0]≥current.month [0]){
        年龄=(current.year [0] - birth.year [0] - 1);
    }其他{
        如果(birth.day [0]&下; = current.day [0]){
            年龄=(current.year [0] - birth.year [0]);
        }其他{
            年龄=(current.year [0] - birth.year [0] - 1);
        }
    }    返回年龄;
}


解决方案

 的#include<&stdio.h中GT;
结构日期{
    月整型[1];
    日整型[1];
    年整型[1];};INT calc_age(结构出生日期,结构日期电流);
INT主要(无效)
{
结构出生日期,电流;
焦炭℃;的printf(输入出生日期(MM / DD / YY):);
scanf函数(%D%C%D%C%D,birth.month,和C,birth.day,和C,birth.year);
的printf(输入日期计算(MM / DD / YY):);
scanf函数(%D%C%D%C%D,current.month,和C,current.day,和C,current.year);的printf(年龄为%d年\\ n,calc_age(出生,电流));返回0;}INT calc_age(结构出生日期,结构日期电流){
INT年龄;如果(birth.month [0]&下; current.month [0]){
    年龄=(current.year [0] - birth.year [0]);
}否则如果(birth.month [0]≥current.month [0]){
    年龄=(current.year [0] - birth.year [0] - 1);
}其他{
    如果(birth.day [0]&下; = current.day [0]){
        年龄=(current.year [0] - birth.year [0]);
    }其他{
        年龄=(current.year [0] - birth.year [0] - 1);
    }
}返回年龄;
}

您应该之前定义结构

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 in

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

while 'parameter 1 ('birth') has incomplete type' and ' parameter 2 ('current') has incomplete type' errors appear in

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

Help is appreciated, thanks!

#include <stdio.h>
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]);
    } 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;
}

解决方案

#include <stdio.h>
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;
}

You should define the struct before main

这篇关于如何解决&QUOT;参数具有不完整的类型&QUOT;错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆