have a conflicting types error [closed]

2019-09-21 04:08发布

问题:

when compiling my c file i get this error i can't seem to get my types correct for this program, how would I go about fixing this problem I put up my .h file as well as my .c file

error

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

example4.h code

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

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

example4.c code

#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';
}

回答1:

Your header file declares void h(const Record r);

while your source file declares void h(Record *r)

You fixed the source file, but forgot to fix your header, when you were trying to apply the answer I gave you to this question.