Dvir Naim
Dvir Naim

Reputation: 335

unknown struct error in function C - Linux

I got a little problem.. I wrote a C program in linux that have a struct and a function that gets the struct and the program worked great in one file but when I split it to 2 files (main.c function.c), I've got an error that say that the struct that I use in the function is unknown. Do I need to declare in any way about the struct in the second file? Thanks:)

Upvotes: 0

Views: 137

Answers (1)

pang1567
pang1567

Reputation: 125

you can define the struct in function.h ,in main.c and function.c add this #include"function.h"

the function.h Format like this

#ifndef FUNCTION_H
#define FUNCTION_H
struct some_struct{

}struct_name;
#endif

Upvotes: 2

Related Questions