8 Replies - 964 Views - Last Post: 21 May 2018 - 09:07 PM

#1 TheFerydra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-May 18

How to read a specific word in a text with Irvine?

Posted 16 May 2018 - 09:53 AM

Hello.

I got a proyect where my team has to program a Hangman game. I'm trying to do the part of choosing the words from a text, but I can't find how to properly read the word from a .txt archive. It doesn't help that most info I found doesn't uses Irvine at all.

The idea is that, once a random value from a certain range (Depending the requested difficulty, like 0-10 in easy, 11-20 in normal and 21-30 in hard) is set, the program searchs for the word in that line, so it can be used for the game.


How could I do this?

Is This A Good Question/Topic? 0
  • +

Replies To: How to read a specific word in a text with Irvine?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14852
  • View blog
  • Posts: 59,263
  • Joined: 12-June 08

Re: How to read a specific word in a text with Irvine?

Posted 16 May 2018 - 10:50 AM

Quote

with Irvine

Refresh me again, what is 'Irvine'?
Was This Post Helpful? 0
  • +
  • -

#3 TheFerydra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-May 18

Re: How to read a specific word in a text with Irvine?

Posted 16 May 2018 - 10:52 AM

The Irvine library used with MASM?

http://programming.m...help/index.html
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14852
  • View blog
  • Posts: 59,263
  • Joined: 12-June 08

Re: How to read a specific word in a text with Irvine?

Posted 16 May 2018 - 10:53 AM

Cool. Moving this to the 'assembly' suboforum.
Was This Post Helpful? 0
  • +
  • -

#5 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: How to read a specific word in a text with Irvine?

Posted 16 May 2018 - 08:54 PM

Irvine is not very popular among assembly programmers. It's (I think) mostly used for learning purposes.

Anyway:
you open a file with CreateFile (yes, it creates OR opens a file) to get a file handle.
You read from the file with ReadFile
When you're done, you close the file with CloseHandle

Remember, a disk block is still usually 512 bytes. It's fastest to read disk in 512-byte chunks.
There doesn't seem to be any special routines for text files. You need to treat all files as binary and
handle the text yourself (like finding line ends).
Was This Post Helpful? 0
  • +
  • -

#6 TheFerydra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-May 18

Re: How to read a specific word in a text with Irvine?

Posted 20 May 2018 - 11:18 AM

Hi, it's me again.

I have a .txt that has a series of words, separated each one with a comma. I want it to take that word, and separate it in a series of bytes/words to work with.

For example, if I have "You,are,the,ocean,gray" in my archive, I want my program to turn it into:

chain BYTE "You","are","the","ocean","gray"

How could I do that? And it is possible to do it with the Irvine language?
http://programming.m...help/index.html
Was This Post Helpful? 0
  • +
  • -

#7 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: How to read a specific word in a text with Irvine?

Posted 21 May 2018 - 10:54 AM

Well, Irvine is not language, but a library (for Windows).

First you call CreateFile with pointer to your file name, access mode GENERIC_READ, HowToCreate=OPEN_EXISTING. The call returns the file handle in EAX or INVALID_HANDLE_VALUE if it couldn't open the file.

Then you call ReadFile with the handle returned by CreateFile, pointer to buffer where the call reads the data, size of the buffer, pointer to number of read bytes where the call places the number of bytes it actually could read. Next read reads the next bytes (file handle contains a file offset).

Then you manipulate the bytes in the buffer just like any string.

Then you read and manipulate, read and manipulate, ... as many times as you need to.

Then, at the end, you call CloseHandle with the file handle.

I don't remember Intel assembly well enough to write an example.

This post has been edited by turboscrew: 21 May 2018 - 10:57 AM

Was This Post Helpful? 1
  • +
  • -

#8 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: How to read a specific word in a text with Irvine?

Posted 21 May 2018 - 11:25 AM

This guy gave a link to a program that reads text from a file using Irvine (check his link).
http://masm32.com/bo...g13524#msg13524
Was This Post Helpful? 0
  • +
  • -

#9 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,107
  • Joined: 03-April 12

Re: How to read a specific word in a text with Irvine?

Posted 21 May 2018 - 09:07 PM

In a hangman, I'd reserve enough memory space for the whole file and read the file there. Then I'd organize it in words:
I'd allocate enough memory space for pointers to the words and a place for the word count.
Then I'd set the first pointer to point to the beginning of first word.
Then in a loop:
get character (byte)
if character is ",", its the end of word
replace "," by 0 (end of string marker)
increment word count
set next pointer (word[word_count]) to point to the next byte (beginning of next word)

loop until all bytes read into the file buffer are handled

Now you have "array of char pointers" to the strings, and 'word_count' is the number of strings.

If you have newlines in the file, they need to be skipped too, so I'd also skip bytes 0x0D (CR) and oxoA (LF).

This post has been edited by turboscrew: 21 May 2018 - 09:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1