Okay, I have a main source called main.c, a header file called test.h, and another class called handBeraknare.c.
Im trying to make my code a bit more readable by transfeering some of my methods to the class handBeraknare.c.
So in main.c i have a struct that looks like this:
typedef struct kort{
int draget;
char farg;
int nummer;
struct kort *next;
}kort; `
In main.c i create a couple of these using kort k=(kort*)malloc(sizeof(kort)); and put them into an array. What im trying to achive is to send this array of kort to a function in handBeraknare.c but I get some sort of weird error "in file included from handBeraknare.c".
Im gussing this has to do with the headerfile now knowing what "kort" is (my struct). Anyway, here’s some of the code:
// in test.h
int beraknaFarg(kort kortHand[]);
// in handBeraknare.c
#include <stdio.h>
#include "test.h"
int beraknaFarg(kort kortHand[]){
char c = kortHand[0].farg;
int i;
for (i=1;i<5;i++){
if (kortHand[i].farg!=c){
printf("inte färg");
system("pause");
//Spelaren har inte färg. Retunera 0
return 0;
}
}
//Spelaren har färg. Retunera 1
printf("!!!!färg");
system("pause");
return 1;
}
//part of the main class. Calling function test()
// which calls the method beraknaHand which exists in handBeraknare.c
#include "test.h"
...
int main(int argc, char *argv[])
{
test();
}
// the testfunction in my mainclass
void test(){
char farg[4]={'S','K','R','J'};
int nummer[14]={0,2,3,4,5,6,7,8,9,10,11,12,13,14};
kort kortArray[52];
kort kortHand[5];
kort *k;
k=(kort*)malloc(sizeof(kort));
k->farg='s';
k->nummer=5;
kortHand[0]=*k;
k->farg='s';
k->nummer=11;
kortHand[1]=*k;
k->farg='s';
k->nummer=12;
kortHand[2]=*k;
k->farg='s';
k->nummer=11;
kortHand[3]=*k;
k->farg='s';
k->nummer=9;
kortHand[4]=*k;
beraknaFarg(kortHand);
Make test.h to read
and remove the
typedeffrom main.c