jaycee99
30th July 2009, 08:06
I'm using seq.eof() to check whether is it End Of File, which the file only contain one word for example testing. But it's not working. I tried to press enter after the word testing, then it's work. Any idea to solve this without pressing enter?

manish_patel
30th July 2009, 09:32
Have you tried open mode "t" in Seq.open() function?

You should specify the "t" option when reading from or writing to a text file on Windows NT systems (for example, "rt+"). This ensures that line separators and EOF characters are handled correctly.

jaycee99
30th July 2009, 11:43
Hi Manish,

I tried the method that you suggested. Still not working. I create one .txt file and type "testing and then press enter" - working, but if i just type "testing" without press enter it direct go to break condition. if i din use seq.eof() to check whether is end of file, then it will continue loop cos of the while loop that i used. Below is how i write the script:


fname = seq.open(ascii.file, "rt+")

while(true)
nFlag = seq.gets(file.rec, 1024, fname)

if seq.eof(fname) <> 0 then
break
endif
endwhile

george7a
30th July 2009, 12:33
Here is a working example from a code I wrote:

save.file = seq.open(filename, "r")
while not seq.eof(save.file)
cont = seq.gets(line, MAX_LINE, save.file)
if cont<>0 then break endif
| do what ever you want with the text...
endwhile
seq.close(save.file)

mark_h
30th July 2009, 17:53
Or

while seq.gets(buff,1024,inputfile)=0
| Do your stuff here.
endwhile


This seems to work for us on UNIX platform, not sure about other platforms.

jaycee99
30th July 2009, 18:47
Hi George,

Thanks a lot. It's work perfect.

Virender
17th July 2011, 08:37
I was also using the same way as described by you but I was missing 'cont' variable usage, now my function also working perfectly.

Thanks
Vir