Re: [Dev-C++] Choose a word from a .txt file
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2008-06-03 08:32:09
|
Why do you talk about scrit? This is the Dev-C++ list, where people normally uses Dev-C++ to write C or C++ applications. The traditional use of the word 'script' is for some interpretative programming - often in a batch file or similar. Anyway - is the file sorted? Does it contain a huge number of words? If no to any of the above two questions: Open file. Read one line into a buffer (for example with fgets()). Find the first separator character (space, tab or whatever the file is using). Replace the separator with a '\0'; Compare start of line with the word you want to match. If no match, load next line and repeat. If match, step past the separator and then eath any more separator characters. Locate the '\n' at end of the read line, and replace with a '\0'; Emit the extracted answer. If the file is huge and sorted, get the file size. Move to the middle of the file. Read one (possibly partial line). Read the next line. Extract the word and see if you are above/below the requested language. If you found the word - extract answer. If word too large, move back to one quarter of the file and repat. If word was too small, seek to 75% of file and repeat. All the time remember the <min,max> range that the expected word must be in. Note that <min> and <max> should represent the start position of text lines, (or the end-of-file) so when you specify <min> as seek offset, you do not have to thow away any potentially partial text lines - you know that it is a full line and can check that word immediately. /pwm On Tue, 3 Jun 2008, Alexsandro Meireles wrote: > Dear users, > > How can I write a script to look a word in a .txt file with two columns (one is the word and the other is the answer I need) and give an answer which is in the second column. In other words, a user types a word, then the script match it with a word in a .txt file (first column) and gives the answer (second column). > > Thanks in advance! > > Alex. > _________________________________________________________________ > Cansado de espaço para só 50 fotos? Conheça o Spaces, o site de relacionamentos com até 6,000 fotos! > http://www.amigosdomessenger.com.br |