2016-11-04 70 views
1

我有2个.c文件,我将尝试调用read_cfg(struct)来分配结构中的数据,但我收到错误的“冲突类型” .h文件中冲突的类型为read_cfg()

example.c

#include<stdio.h> 
#include"example.h" 

struct config /structure 
{ 
char data[10]; 
}; 

int main() 
{ 
int n=0; 
struct data d; 
read_cfg(&d); //function call 
} 

example.h文件

#ifndef EXAMPLE_H 
#define EXAMPLE_H 
extern void read_cfg(struct); //ERROR 

examplelib.c

struct config //structure 
{ 
    char data[10]; 
}; 


void read_cfg(struct config_data *cfg) //function implementation 
{ 
struct config_data tmp; 
strcpy(tmp.data,"helo"); 
cfg=&tmp; 
} 

任何帮助将是我

感谢

+0

请检查您的问题中的代码:您有3种不同的结构类型:'struct config','struct data'和'struct config_data'。这些应该是同一类型吗?请阅读[mcve]。 – user694733

回答

1

的extern空隙read_cfg(结构); //错误

错误是因为您的参数类型不匹配。应该是void read_cfg(struct config_data *)

顺便说一句,你不需要extern关键字的功能 - 默认情况下,功能有外部链接(除了静态功能)。

0

您的read_cfg()功能(在example.h)和你的read_cfg()定义(在examplelib.c)声明不匹配有用。 在example.h更改声明:

extern void read_cfg(struct config_data *cfg);