Thread: Data structure to record football season game results

  1. #16
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    Perfect! Thanks STD and everyone else, it works.

  2. #17
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    You are welcome

    PS : I like to see the initialization in a function

  3. #18
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    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
    
    
    }

  4. #19
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Is this what you are looking for?
    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;
    }
    Why static? Because if i remove it , it will be a local variable.

    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.

  5. #20
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    This will work nicely, thank you.

  6. #21
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structure, user input and printing out results
    By alvarito in forum C Programming
    Replies: 3
    Last Post: 10-04-2011, 11:04 AM
  2. Record data types....Structures
    By Lego_TeCh in forum C Programming
    Replies: 6
    Last Post: 08-31-2009, 11:36 AM
  3. how to make function return value go to structure record
    By Tom Bombadil in forum C Programming
    Replies: 1
    Last Post: 05-27-2009, 03:38 PM
  4. linear search for structure (record) array
    By jereland in forum C Programming
    Replies: 3
    Last Post: 04-21-2004, 07:31 AM
  5. Add to my football strategy text game
    By real_cozzy in forum Game Programming
    Replies: 6
    Last Post: 01-20-2002, 05:09 PM