Re: Help please
- Posted by DerekParnell (admin) Feb 20, 2012
- 1141 views
johnrpm said...
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)