1
I’m doing a C project, and I have 3 files:
1 . c containing the definitions of functions and structs.
1 . h containing the prototypes of these functions and structs
Ae1 . c containing the main.
No . c with the definitions, I defined the struct:
typedef struct vector {
int numDePosicoes;
double vetor[5000];
}ESTRUCT;
And in the main method, I try to create an instance of that struct as follows:
int main(int argc,char* argv[]) {
ESTRUCT vetor;
//criando separadamente um ponteiro para a struct
ESTRUCT *ponteiroPraVetor = &vetor;
But gcc accuses error: "error: Unknown type name ESTRUCT'"
Both in the creation of the struct, and in the creation of the pointer for it.
Note: I am using a Makefile to build the program, follows it below:
CFLAGS=-Wall
Roteiro5exe: mainr5.o Roteiro5.o
mainr5.o: mainr5.c Roteiro5.h
Roteiro5.o: Roteiro5.c Roteiro5.h
clean:
rm *.o
NOTE: When I put all the code in the same file, and simply compile it, it works. Maybe the problem is in Makefile. Someone can see it?
Ah, the contents of the file. h is this: void initializ_vector(struct vector *v1); struct vector vector vector;
– Lucas Pletsch
Includes placed in the two files . c: the definitions and the main: #include <stdlib. h> #include <stdio. h> #include <pthread. h> #include <string. h>
– Lucas Pletsch
But you are doing
include
of the file where you set thestruct
?? It seems that...– Christian Felipe
Cristian, in the file. h I did I put the "prototype" of the struct (I don’t even know if I need it). Which is the following: struct vector nameQualquerDeStruct and in the file. c (without the main) I put the complete struct ( typedef struct estructe{ ..... } ESTRUCT, complete with your content. What do you mean by define? Declare the complete struct?
– Lucas Pletsch
Forget it, I’ve seen the answer. Thanks
– Lucas Pletsch