-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