This may sound like a stupid question, but someone has to ask it...
How does Naalaa detect EOF (End Of File)? There are all sorts of commands to open read, write, close. But I could not find a command that detects the EOF when "reading" a file. Have I missed something?
I have a program that reads a text file. I need to assign the contents of each line to a specific variable/array, but I do not want the program to "read" beyond the "end of file".
I know how to do all the assigning etc, what I do not know, is how to stop reading the file when it gets to the end of the file.
Any thoughts?
Thank you.
J
(03-14-2026, 05:09 AM)johnno56 Wrote: [ -> ]This may sound like a stupid question, but someone has to ask it...
How does Naalaa detect EOF (End Of File)? There are all sorts of commands to open read, write, close. But I could not find a command that detects the EOF when "reading" a file. Have I missed something?
I have a program that reads a text file. I need to assign the contents of each line to a specific variable/array, but I do not want the program to "read" beyond the "end of file".
I know how to do all the assigning etc, what I do not know, is how to stop reading the file when it gets to the end of the file.
Any thoughts?
Thank you.
J
I don't know what function you're using, but if I remember correctly they all return an unset (null) variable when eof is reached.
Code:
foo = fread(f)
if foo = unset
' eof reached.
endif
All I am doing is "reading" a file of words for a hangman game and could not remember if N7 had an EOF() function.
The code used is a simple: open the file; create a loop to read and store a word; count the word; until end of file; close file.
I will incorporate your 'unset' option. Sounds like fun. Thank you!
(03-14-2026, 06:31 PM)johnno56 Wrote: [ -> ]... for a hangman game ...
...guessing letters to figure out a word... It's kind of a classic from the early days of computer gaming.
Really excited to try your version when it's ready !
![[Image: 1049636-hangman-atari-2600-hmmm-just-one...re-out.png]](https://cdn.mobygames.com/screenshots/1049636-hangman-atari-2600-hmmm-just-one-more-letter-to-figure-out.png)
I am still getting the "core" of the game to function correctly. Then I can move onto how the game looks. The image you provided reminds of the type of graphics created by the VZ200 (Laser200) computer back in the early 80's.... lol
(03-15-2026, 05:50 AM)johnno56 Wrote: [ -> ]I am still getting the "core" of the game to function correctly....
I have something very simple in mind that could possible point toward the "core" of the game. It's nothing big, but just an idea that might help making sense. Either way, keep going. You're closer than you probably think !
Code:
'----------------
' Initialization
'----------------
set window "Mini Hangman",500,200
randomize time()
constant word_max = 12, max_tries = 6
black = [0,0,0]
white = [255,255,255]
' file management
f = openfile("dico.txt")
word = []
for i = 1 to word_max
word[i] = fread(f)
next
free file f
' pick random word
w = word[rnd(1, word_max)]
length = len(w)
' reset game state
guessed = ""
wrong_count = 0
'-----------
' Main Loop
'-----------
while wrong_count < max_tries
'clear screen
set color black
cls
set color white
display = ""
for i = 0 to length - 1
c = mid(w, i, 1)
found_in_guessed = 0
' Check if character is in guessed string
for j = 0 to len(guessed) - 1
if mid(guessed, j, 1) = c then
found_in_guessed = 1
endif
next
' Show letter or underscore
if found_in_guessed = 1 then
display = display + upper(c) + " "
else
display = display + "_ "
endif
next
set caret 10,20; wln "Word: " + display
' Check win condition
won = 1
for i = 0 to length - 1
c = mid(w, i, 1)
if asc(c) >= 97 and asc(c) <= 122 then
found = 0
for j = 0 to len(guessed) - 1
if mid(guessed, j, 1) = c then found = 1
next
if found = 0 then won = 0
endif
next
if won = 1 then
wln " YOU WIN! The word was: " + upper(w) + " "
wait 6000
end
endif
' Get input
write "Guess a letter (a-z): "
guess = lower(rln(1,TYPE_STRING))
guessed = guessed + guess
found = 0
for i = 0 to length - 1
if mid(w, i, 1) = guess then found = 1
next
if found = 0 then
wrong_count = wrong_count + 1
pln "wrong count :"+wrong_count
endif
wend
'-----------
' Game Over
'-----------
wln " GAME OVER! The word was: " + upper(w) + " "
temp=rln()
wait 3000
Very nice. True. It was simple... I am a BIG fan of simple! Nicely done!