形式参数1的类型不完整

时间:2014-12-19 15:58:24

标签: c struct

我正在尝试编写一个程序,用结构添加两个有理数 这是代码

#include <stdio.h>
#include <stdlib.h>

struct Fraction{
                int numerator ;
                int denominator ;
                };

int mainMenu(void);
struct Fraction readStructure(void); /*this works well*/
struct Fraction add(struct Fractoin num1, struct Fraction num2);/*this doesn't*/

int main()
{
    struct Fraction num1 = readStructure();
    struct Fraction num2 = readStructure();

    struct Fraction result = add(num1, num2) ;

    return 0 ;
}
struct Fraction readStructure(void)
{
    struct Fraction temp;

    printf("-> Enter the numerator : ");
    scanf("%d", &temp.numerator);
    printf("-> Enter the denominator : ");
    scanf("%d", &temp.denominator);
    while(temp.denominator == 0)
    {
        printf("--> Zero in the denominator isn't possible.. try again : ");
        scanf("%d", &temp.denominator);
    }

    return temp ;
}
struct Fraction add(struct Fractoin num1, struct Fraction num2)
{
    struct Fraction temp;

    temp.numerator = (num1.numerator * num2.denominator) +
                     (num2.numerator * num1.denominator);
    temp.denominator = num1.denominator * num2.denominator ;

    return temp ;
}

编译器说这是错误的并且给了我那些错误+更多的警告......

error: type of formal parameter 1 is incomplete.
error: parameter 1 ('num1') has incomplete type.

2 个答案:

答案 0 :(得分:3)

struct Fraction add(struct Fraction num1, struct Fraction num2);

分数拼写错误:)

答案 1 :(得分:1)

你已经把:

struct Fraction add(struct Fractoin num1, struct Fraction num2);

但你看看num1的类型,你会发现你拼写错误的分数。你有io错误的方式!