Archived

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

RanBlade

Help please.

Recommended Posts

Ok I know this is a openGL forum. but this is only forum i found so far that has good people on it. But Iam using a fucntion to randomly pick a value and have another function use that random to call a word from a char array but everytime it does this it only displays the first letter... and i cant figure out why... sorry to be posting this on openGL forum.

Share this post


Link to post
Share on other sites
Can you post some code?
Im sure it has nothing to do with your random number selection - its probably how you display the result but to be completely sure, i need to see some code. You never know where the bug might be

Share this post


Link to post
Share on other sites
int LOW = 0;
int HIGH = 5;

int WordPicker();
char Word();




int WordPicker()
{
int nWord;

time_t seconds;
time(&seconds);
srand((unsigned int) seconds);

nWord = rand() % (HIGH - LOW) + LOW;



return nWord;
}


char Word()
{
int nWord = WordPicker();

char* szWord[] = {"online", "game", "hat", "word", "diablo", "mom", "\0"};



return *szWord[nWord];
}


int main()
{
cout<< WordPicker() << " " << Word() << "\n";

return 0;
}

Share this post


Link to post
Share on other sites
While i go through the debugger it shows that szWord[nWord] is correct but i cant get it to display the full word... hrmmm

Share this post


Link to post
Share on other sites
char Word()
{
int nWord = WordPicker();

char* szWord[] = {"online", "game", "hat", "word", "diablo", "mom", "\0"};



return *szWord[nWord];
}

your returning only a char not a pointer to a char

change to char *Word()

Share this post


Link to post
Share on other sites
the problem comes because it is returning a char not a char * like it should. try this

char *Word()
{
int nWord = WordPicker();

char* szWord[] = {"online", "game", "hat", "word", "diablo", "mom", "\0"};



return szWord[nWord];
}

Share this post


Link to post
Share on other sites