eof() problem

Just starting out? Need help? Post your questions and find answers here.
wmorton
User
User
Posts: 81
Joined: Fri Jul 25, 2003 5:39 pm

eof() problem

Post by wmorton »

Hi, I am accessing a text file with readfile() and then reading strings one by one which I am writing to another text file. However, the program seemingly runs forever, never getting out of the While/Wend section, as if there is no end to the original file:

Code: Select all

    While Eof(#ORIGINAL) = 0
      
      Repeat
        current_string$ = ReadString(#ORIGINAL)
        WriteStringN(#SHUFFLED, current_string$)
      Until current_string$ = "    <ITEM"
      
      position.f = ValF(RemoveString(ReadString(#ORIGINAL), "      POSITION "))
      length.f = ValF(RemoveString(ReadString(#ORIGINAL), "      LENGTH "))
      
      If counter = 0
        WriteStringN(#SHUFFLED, "      POSITION " + StrF(position.f))
        WriteStringN(#SHUFFLED, "      LENGTH " + StrF(length.f))
        new_position.f = prev_position.f + prev_length.f
        counter = 1
      Else
        WriteStringN(#SHUFFLED, "      POSITION " + StrF(new_position.f))
        WriteStringN(#SHUFFLED, "      LENGTH " + StrF(length.f))
        new_position.f = prev_position.f + prev_length.f + ValF(GetGadgetText(#SPACING))
      EndIf
      
      prev_position.f = new_position.f
      prev_length.f = length.f
      
    Wend
Any ideas what I'm doing wrong?

Thanks!
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

In my opinion, the While loop you're using is a little unsafe since you use ReadString many times during this one loop.
Proud registered Purebasic user.
Because programming should be fun.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Use the debugger and stop the program to see where it is stuck. I'm betting it's somewhere in this code:

Code: Select all

      Repeat 
        current_string$ = ReadString(#ORIGINAL) 
        WriteStringN(#SHUFFLED, current_string$) 
      Until current_string$ = "    <ITEM"
Post Reply