1. Help please
- Posted by johnrpm Feb 20, 2012
- 1187 views
I have a text file with a number on each line, at certain points in the file, (end of image width) I have a character R, I want to find this character in insert printhead offsets, the code below may explain.
file_numR= open("c:/red.jet", "r") file_numR2= open("c:/red2.jet","w") trace(1) lineR = gets(file_numR) for t = 0 to incR do i = equal(lineR,['R']) while i = 0 do -------- 1 true 0 false puts(file_numR2, (lineR)) lineR = gets(file_numR) i = equal(lineR[1],'R') end while a1 = where(file_numR2) i2 = a1-2 i1 = seek(file_numR2,i2) for R = 0 to TotalOffset do puts(file_numR2, '\n') puts(file_numR2, "0.xxx") -- insert test value end for lineR = gets(file_numR) puts(file_numR2, '\n') end for close(file_numR) close(file_numR2)
But I get this error message..... attempt to subscript an atom (reading from it)
Can anyone tell me what I am doing wrong, please keep it simple, i'm not very bright.
2. Re: Help please
- Posted by DerekParnell (admin) Feb 20, 2012
- 1141 views
I have a text file with a number on each line, at certain points in the file, (end of image width) I have a character R, I want to find this character in insert printhead offsets, the code below may explain.
Just to clarify, I assume this 'R' you are looking for is on a line of its own.
The main problem is that you are not testing for end-of-file. The gets() function returns -1 when it comes to the end of a file, and of course you can't subscript an atom. Also, when a line is returned by gets(), it includes the end-of-line marker so you might want to strip that off too.
Try this ...
file_numR= open("c:/red.jet", "r") file_numR2= open("c:/red2.jet","w") lineR = gets(file_numR) for t = 0 to incR do if atom(lineR) then exit -- end of file. end if lineR = trim(lineR) -- Strip off leading and trailing whitespace etc. i = equal(lineR,"R") while i = 0 do -------- 1 true 0 false puts(file_numR2, lineR) lineR = gets(file_numR) if atom(lineR) then exit -- end of file. end if lineR = trim(lineR) -- Strip off leading and trailing whitespace etc. i = equal(lineR,"R") end while a1 = where(file_numR2) i2 = a1-2 i1 = seek(file_numR2,i2) for R = 0 to TotalOffset do puts(file_numR2, '\n') puts(file_numR2, "0.xxx") -- insert test value end for puts(file_numR2, '\n') lineR = gets(file_numR) end for close(file_numR) close(file_numR2)
3. Re: Help please
- Posted by johnrpm Feb 20, 2012
- 1153 views
Well, is that it, I told you I was simple, been trying different things but had not thought about EOF, thank you Derek, and thank you for all the work you developers have done to make Euphoria so good.