After searching for a while. I code a simple program to try and solve my bigger problem easier having little or no success. This is the code which works fine in main:
typedef struct nimaginario{
int parte_real;
int parte_imaginaria;
}nimaginario;
int suma(nimaginario *n){
return n->parte_real + n->parte_imaginaria;
};
#include <stdlib.h>
int main(){
nimaginario *num = malloc(sizeof(nimaginario));
num->parte_real = 1;
num->parte_imaginaria = 2;
int a = suma(num);
}
Then I try dividing it into the different parts it should be organized in. As to say: prueba.c, prueba.h, and main.c
prueba.h:
#define PRUEBA_H
#ifndef PRUEBA_H
typedef struct nimaginario{
int parte_real;
int parte_imaginaria;
}nimaginario;
int suma(nimaginario *n);
#endif
prueba.c:
#include "prueba.h"
int suma(nimaginario *n){
return n->parte_real + n->parte_imaginaria;
};
main.c:
#include <stdlib.h>
#include "prueba.h"
int main(){
nimaginario *num = malloc(sizeof(nimaginario));
num->parte_real = 1;
num->parte_imaginaria = 2;
int a = suma(num);
}
In the first place I compiled with the command 'gcc main.c' In second place I did as follows: 'gcc prueba.c main.c'
and for this second time and this specific try (out of one hundred) I get this errors:
prueba.c:3:10: error: unknown type name `nimaginario'
main.c: In function `main':
main.c:18:2: error: unknown type name `nimaginario'
main.c:18:35: error: `nimaginario' undeclared (first use in this function)
main.c:18:35: note: each undeclared identifier is reported only once for each function it appears in
main.c:19:5: error: request for member `parte_real' in something not a structure or union
main.c:20:5: error: request for member `parte_imaginaria' in something not a structure or union
I think I have tried everything and anything. And seen all the errors I could see. I've also googled around a lot, and searched here in Stackoverflow with no success what so ever.
Things I've tried:
I just fail to have a hammer close. I feel so numb It has just been a year without C...
You have an issue with the include guards ;-)
You want to check first then define it, not the other way around.
#define PRUEBA_H
#ifndef PRUEBA_H
...
should be
#ifndef PRUEBA_H
#define PRUEBA_H
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With