On Mar 23, 11:19 am, Finger.Octo...@gmail.com wrote:
> Hi,
>
> Well, I want to read the contents of file in a character array.
> Actually, I am doing this for Hangman(game). I want to read the
> contents of file in a character array, so that I can pick a word out
> of it and then generate dashes(-) at it's place. Can anyone please
> guide me on this one?
Read the wordlist into an array.
Pick a random number between 1 and the number of items read. The C-
FAQ tells how to do this.
Choose the word at that location in the array.
It will be a pain in the wazonga if you try to seek around in the
file.
If there is too much data to load into memory, you can read the file
once to find out how many things there are.
Then, choose a random number between 1 and the number of items that
you read.
Finally, discard (that number - 1) inputs and keep the next one.
|