Hey I've got a minor problem in the code i'm writing, basically what i've done is to fill an character array with text i've read in from a text file.
So the code for that is like this, tempstring is a line of text read in from the text file:
Code to populate array (it's a 7x80 character array):
Code:
tempString = strtok( information, "\t" );
int i = 0; //int for iterating through text array
while (tempString != NULL ) {
printf("Cutting line \n");
strncpy(playerInformation[i], tempString, LINESIZE);
//add to player struct
tempString = strtok( NULL, "\t" );
i = i + 1;
}
This is how i'm trying to fill my struct, the definition of this is below:
Code:
typedef struct playerData *playersData;
struct playerData {
char *name; //name of player
char *country; //country of origin
char *innings; //innings
char *runs; //runs
char *nOut; //not out
char *hScore; //highscore
char *hsNOut ;//if the high score is also not out
struct playerData *next; //pointer to the next player
};
//Create the struct to hold the players
typedef struct playerList pList;
struct playerList {
playersData *person;
pList *next;
};
And here's my code to try and build up a player to insert
Code:
playersData player = {playerInformation[0], playerInformation[1],
playerInformation[2], playerInformation[3], playerInformation[4],
playerInformation[5], playerInformation[6]};
Now the error i'm getting is:
warning: excess elements in scalar initializer
warning: (near initialization for ‘player’)
I'm guessing that it's something to do with me not passing the right values to the array, but for the life of me I have no idea what to do to fix it. I know that a better way would be to build up the player in the loop i create the array in, but once again I don't know how to do that.
I'm happy for any advice in either direction. Cheers