有冲突的类型错误 [英] have a conflicting types error

查看:240
本文介绍了有冲突的类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当编译我的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);



< r)



您修复了源文件,但忘记修复标题,当您尝试应用 answer我给了你此问题


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

解决方案

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.

这篇关于有冲突的类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆