I have the following struct
struct statistics {
int result[100],steps[100],gamecounter;
float time[100];
};
typedef struct statistics GAMEST;
In my functions I call it like this
GAMEST gamesStruct;
gamesStruct.result[2]=res;
gamesStruct.steps[2]=step;
gamesStruct.time[2]=tim;
At the moment I assign values to the struct its all good and the data are fine. But when I try to print value that I assigned previously for example gamesStruct.result[0] what I get is a big number which looks like a memory address like if the gamesStruct.result[0] is empty.
Any ideas ?
Here is some more code
int stats(int res,int gamenum,int step,float tim,int counter){
GAMEST gamesStruct;
char vic[3][7];
if(gamenum>=0){
strcpy(vic[0],"Draw");
strcpy(vic[1],"Victory");
strcpy(vic[2],"Loss");
gamesStruct.result[gamenum]=res;
gamesStruct.steps[gamenum]=step;
gamesStruct.time[gamenum]=tim;
}else{
printf("Stats per game :\n\n");
system("pause");
for(int i=0;i<=counter;i++){
int tmp=gamesStruct.result[0];
printf("%d",gamesStruct.result[0]);
system("pause");
system("pause");
printf("Game %d : %s in %d moves and %f seconds\n\n",i+1,vic[tmp],gamesStruct.steps[i],gamesStruct.time[i]);
}
printf("out");
system("pause");
int ressum[3]={0,0,0};
int stepsum=0;
int timesum=0;
printf("2");
system("pause");
for(int i=0;i<=counter;i++){
ressum[gamesStruct.result[i]]=ressum[gamesStruct.result[i]]+gamesStruct.result[i];
stepsum=stepsum+gamesStruct.steps[i];
timesum=timesum+gamesStruct.time[i];
}
float resmid[3],stepmid,timemid;
resmid[0]=resmid[0]/(counter+1);
resmid[1]=resmid[1]/(counter+1);
resmid[2]=resmid[2]/(counter+1);
stepmid=stepmid/(counter+1);
timemid=timemid/(counter+1);
printf("\n\nAverage stats for %d games:\n\n",counter+1);
printf("\nVictories :%f Losses :%f Draws :%f \n",resmid[1],resmid[2],resmid[0]);
printf("\nAverage moves :%f and Time :%f\n\n",stepmid,timemid);
}
return(0);
}
If gamenum is bigger or equal to 0 my function assigns values properly to the struct. But when i try to print them my program crashes because the data is wrong
I want to point out that I HAVE assigned values before I try to access them, thats is my problem