Hello all, I have two problems that I don't really know how to eliminate. 1. Imagine I have a txt file that contains several words, each in a new line. How would I go and use a random function (I have one) to get one of these words out of the text file into the buffer. 2. Imagine now I have this word in my buffer. How can I search the word/string to find a specific character (that can possibly occur more than once in this string. Hope that anyone can help me, maybe with a code snippet? ;) Best regards Stefan
Posted on 2000-12-28 09:04:00 by Stefan Krause
hi, 1. search for cr/lf (10/13) first try to copy all the words into a buffer. say your file contains 20 lines with one word in each line and your random number generator gives you a 5. then i would scan this word-buffer 5 times for cr/lf (cariage return/line feed) to obtain the fith line/the fith word... maybe you find some other way without putting all this data into the buffer first... 2. here's the code-snipet to search for a specific character. in my example we've got the string "hallo.txt" and this program searches for "." .DATA msg db "hallo.txt",0 msg1 db "true",0 msg2 db "false",0 .CODE start: cld lea edi,OFFSET msg mov al,"." mov ecx,sizeof msg repnz scasb jnz @nope invoke MessageBox,NULL,addr msg1,addr msg,MB_OK jmp @exit @nope: invoke MessageBox,NULL,addr msg2,addr msg,MB_OK @exit: invoke ExitProcess,NULL END start
Posted on 2000-12-28 10:15:00 by drcmda
Hmm, okay drcmda, the second part is clear now but what about the first? I still don't understand how to get one string out of this txt file by random. Maybe one can get a bit more precise on this? Stefan
Posted on 2000-12-28 11:11:00 by Stefan Krause
1. create these vars .DATA? buffer db 1000 dup (?) wordnbr db ? random db ? pointer dd ? 2. read file "words.txt" to "buffer" 3. copy the number of words in your file to "wordnbr" 4. copy the random result from 0-wordnbr into "random" 5. kill all cr/lf and paste a 0 (zero) 6. do something like this: push offset buffer pop pointer looop: invoke lstrlen,pointer add pointer,eax dec wordcount jnz looop 7. now the pointer var points on the random word... i hope that will help. the hard part is to kill the cr/lf bytes, maybe you do this cr=0 lf=" " (cr=ascii 10 and lf=ascii 13). sorry but i must leave work now and i'm to lazy to give you a more detailed solution but i think it's more fun to do things alone anyway ;)
Posted on 2000-12-28 11:30:00 by drcmda
Yeah, thank you for your support and of course you are right when you say that it is more fun to do it yourself. That is what I think but I need some kind of help to find the correct direction. I think I will be able to do it now. BTW, you definitly seem to have a very interesting work when you can sit there and watch the Win32ASM board all the time ;) Best regards Stefan
Posted on 2000-12-28 11:48:00 by Stefan Krause
There are a number of string functions in Hutch's masm32.lib James
Posted on 2000-12-28 17:16:00 by jcfuller
Rather then having to search ut stings, I saw a nice trick used in IDA. The text strings are all held in a single binary file. I forget exact details, so I'll pretend I do remember and tell you how I would recreate this. The file has three sections. Section 1 is a single dword being a count of haw many strings the resource contains (I'm pretty sure the orgional did not boast this feature, but it's a nice addition). Section 2 is a series of dword offsets to the starting positions of each string. Finally, section 3 is the strings themselves. However, each string is preceeded by it's dword character count. Done in this mannor, there is never any searching, and any data (including embeded nulls and or CR/LF) may be enbeded in the data. To get a random word (or sentence or paragraph or float number or..), one first reads the first dword to get N (how many there are), makes a random number from 1 to N, reads location for A, then reads characters starting at . Gonna be very fast to access that way.
Posted on 2000-12-29 00:53:00 by Ernie