-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';
}
有關此問題的前言,請參見[錯誤:只讀位置的分配](http://stackoverflow.com/questions/16226313/error-assignment-of-read-only-location)。 – 2013-04-25 23:55:38
「我將如何解決這個問題」 - 顯然,通過使類型相同。發佈之前,你甚至看過你的代碼嗎? – 2013-04-26 01:35:38