本文介绍了有冲突的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当编译我的c文件我得到这个错误i似乎不能得到我的类型正确的程序,我将如何解决这个问题我把我的.h文件作为我的.c文件 错误 example4.c:35 :错误:'h'的冲突类型 example4.h:8:错误:以前声明的'h'在这里 example4.h code typedef struct { int x; char s [10]; }记录; void f(Record * r); void g(Record r); void h(const record r); example4.c代码 #include< stdio.h> #include< string.h> #includeexample4.h int main() {记录值,* ptr; ptr =& value; value.x = 1; strcpy(value.s,XYZ); f(ptr); printf(\\\Value of x%d,ptr - > x); printf(\\\Value 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'; } 解决方案您的头文件声明 void h(Record *)时,c $ c> void h(const Record r); 您修复了源文件,但忘记修复标题,当您尝试应用 answer我给了你到此问题。 when compiling my c file i get this errori can't seem to get my types correct for this program, how would I go about fixing this problemI put up my .h file as well as my .c fileerrorexample4.c:35: error: conflicting types for ‘h’example4.h:8: error: previous declaration of ‘h’ was hereexample4.h codetypedef 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';} 解决方案 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. 这篇关于有冲突的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 14:54
查看更多