-2

编译我的 c 文件时出现此错误我似乎无法为该程序正确设置类型,我将如何解决这个问题我提出了我的 .h 文件以及我的 .c 文件

错误

example4.c:35: error: conflicting types for ‘h’
example4.h:8: error: previous declaration of ‘h’ was here

example4.h 代码

typedef struct{
        int x;
        char s[10];
}Record;

void f(Record *r);
void g(Record r);
void h(const Record r);

example4.c 代码

#include <stdio.h>
#include <string.h>
#include "example4.h"

int main()
{
        Record value , *ptr;

        ptr = &value;

        value.x = 1;
        strcpy(value.s, "XYZ");

        f(ptr);
        printf("\nValue of x %d", ptr -> x);
        printf("\nValue of s %s", ptr->s);


        return 0;
}

void f(Record *r)
{
        r->x *= 10;
        (*r).s[0] = 'A';
}

void g(Record r)
{
        r.x *= 100;
        r.s[0] = 'B';
}

void h(Record *r)
{
        r->x *= 1000;
        r->s[0] = 'C';
}
4

1 回答 1

3

你的头文件声明void h(const Record r);

而你的源文件声明void h(Record *r)

您修复了源文件,但忘记修复标题,当您尝试将我给您的答案应用于此问题时。

于 2013-04-25T23:49:59.007 回答