Thread: Problem with pointers to structs

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    On me hyperplane

    Problem with pointers to structs

    Ok, I have been here before and forgot how to do this

    Basically I have a struct declared as:
    typedef struct
        char name[20];
        Uint8 hand[5];
        Uint8 cards;
        Uint32 cash;
        Uint8 active;// If in round or not
        // Applies to bots only 
        Uint8 bluff; 
        Uint8 skill; 
        Uint8 memory;
    In main I create an array of players and pass teh array to a function:
    player *players[G_NUM_PLAY];    
    I pass the players to the function, which compiles fine, but whenever I try and access any of the struct variables my prog gibbs out:
    void InitPlayers(player **p)
        // Set up player
        printf("Name yourself: ");
        GetStr(p[0]->name, 20);
        p[0]->cash = G_START_CASH;
        p[0]->bluff = 0;
        // Set up bots
        Uint8 i;
        for(i=1; i<G_NUM_PLAY; i++)
            p[i]->cash = G_START_CASH;
            strcpy(p[i]->name, GenerateName());
            p[i]->bluff = rand() % 5;
        // Determine who starts as the dealer
        G_DEALER = rand() % G_NUM_PLAY;
        // Print game start status
        printf("You are playing: ");
        for(i=1; i<G_NUM_PLAY-1; i++)
            printf("%s, ", p[i]->name);
        printf("and %s.\n", p[i]->name);
        printf("Each player starts with %u chips\n", p[0]->cash);
        printf("%s starts as the dealer\n", p[G_DEALER]->name);
    What am I doing wrong here?


  2. #2
    Join Date
    Oct 2007
    Inside my computer
    First thing that comes to mind is... did you allocate space with malloc? Since you're creating an array of pointers...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    On me hyperplane
    Oh.. Um.. No lol thanks elysia.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with file handling (pointers)
    By hmk in forum C Programming
    Replies: 5
    Last Post: 09-19-2008, 10:03 AM
  2. Problem with pointers
    By kotoko in forum C Programming
    Replies: 3
    Last Post: 06-12-2008, 05:17 AM
  3. problem using pointers
    By thestien in forum C++ Programming
    Replies: 3
    Last Post: 05-02-2008, 05:02 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. pointers and structs
    By alexir in forum C Programming
    Replies: 0
    Last Post: 10-20-2001, 01:28 AM