Perfect! Thanks STD and everyone else, it works.
You are welcome
PS : I like to see the initialization in a function
Yeah, it would make a real mess of main if I initialized game[] there. There is going to be a lot of messy initialization going on. One last question, currently in init_games() I'm using two lines of code for each initialization, and I wish I could just use one, e.g.
Code:void init_games(game_t *game) { //game_t tempgame = {1,2,3,33.0,47.0}; // game[0] = tempgame; //THIS WORKS game[0] = {1,2,3,33.0,47.0}; // THIS DOESN'T }
Is this what you are looking for?
Why static? Because if i remove it , it will be a local variable.Code:#include <stdio.h> #include <stdlib.h> #include <math.h> typedef struct { int week; int hometeam; int awayteam; float homescore; float awayscore; } game_t; game_t * init_games(game_t *gamePtr) { static game_t game[10] = { {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} , {1,1,1,0.1,0.5} }; gamePtr = game; return gamePtr; } int main(void) { printf("FOOTBALL: \n"); game_t * gamePointer; gamePointer = init_games(gamePointer); printf("%d %f\n",gamePointer[0].week,gamePointer[0].homescore); return 0; }
Damn I like this way of initializing. If I could I would click like to my own post haha
Last edited by std10093; 11-25-2012 at 01:52 PM.
You may want to upgrade your program to use linked lists and save results in a binary file
Fact - Beethoven wrote his first symphony in C