This topic is now archived and is closed to further replies.


Char Arrays?

Recommended Posts

I am beginning to work on the highscore system for my game. I am going to have 10 highscores, the scores will be held in a plain array int Score[10] question is... Is there a way I could store the names for the scores in a char array to coorespond with the score integers? So I could access Score[1] and then Name[1] to get the score and name. Any help would be appreciated. Thanks -Tim

Share this post

Link to post
Share on other sites
I just finished a game that does something very similair. Yes you can use character arrays. The way I did it was to have a struct for a high score that has 2 things in it:
char name[MAX_NAME_LENGTH];
int score;
Then I defined 10 of those structs like this :
(structure name) high_score[10];
To acces the name and score of the first high score you would just do :
high_score[0].name = whatever
high_score[0].score = whatever.
Is there anything more specific that you need to know?

*** Triality ***

Share this post

Link to post
Share on other sites
although zerwit's approach is probably nicer and cleaner, you can access strings in an array that way:

char* ppNames[10];
for(int i=0; i<10; i++)
ppNames = (char*) malloc(256);

then you can just set the strings in the array thru plain calls like
strcpy(ppNames[0], "hiscore");

and don't forget to free the array when you don't need it any more

i hope the code is not going to be too screwed up

Edited by - Ridcully on 4/8/00 12:55:48 PM

Share this post

Link to post
Share on other sites