Help please.

Started by
6 comments, last by RanBlade 21 years, 1 month ago
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.

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

Advertisement
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
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;
}

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

The call to both functions is purely a testing thing.

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

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

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

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()
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];
}
ASCII stupid question, get a stupid ANSI
Thank you very much guys. for some reason i didnt see that dunno why but i didnt. thanks a lot...

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

This topic is closed to new replies.

Advertisement