PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed

Re: How to load the whole file?

 List
Subject: Re: How to load the whole file?
Poster: user923005
Date: 23 Mar 2007 12:50:15 -0700
Related Postings: 1 2 3 4 5 6
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.

 

Page2Go2.com is not responsible for content of this message.