Re: File I/O Difficulty
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Jun 20, 1998
- 796 views
At 05:32 PM 6/19/98 -0400, you wrote: >---------------------- Information from the mail header ----------------------- >Sender: Euphoria Programming for MS-DOS <EUPHORIA at LISTSERV.MUOHIO.EDU> >Poster: Alan Tu <ATU5713 at COMPUSERVE.COM> >Subject: File I/O Difficulty >------------------------------------------------------------------------------- > >I am trying to read a file in for alteration on a byte-by-byte level. > >-----filedemo.ex >include file.e >include input.e >clear_screen() >sequence s >integer file_i, file_o, seek_success >s = input("Enter input path and filename: ") >file_i = open(s, "rb") >sequence file_proc >integer file_length >cseek_success = seek(file_i,-1) >file_length = where(file_i) >seek_success = seek(file_i,0) > >for x = 1 to file_length do > file_proc[x] = getc(file_i) >end for >-----end filedemo.ex > >Well, I got an error. > >-----ex.err > >crypt.ex:15 >variable file_proc has not been assigned a value = > >=2E.. >-----end ex.err > >Taking the hint, I then assigned to sequence file_proc to an empty sequen= >ce >before I entered the for loop. Well, it complained that I was assigning >something to a 0-length sequence. This makes sense, only I expected my >program would allocate storage dynamicly. > >So, would someone please tell me how to resolve this error? Or, if anyon= >e >has a better suggestion, please let me know too. > >Thankx > >Alan You are addressing specific elements of the sequence file_proc that don't exist by using: file_proc[x]= if x=1 and file_proc={} then you are attempting to write to element 1 of a zero length sequence. To initialze the sequence for this kind of access use: file_proc=repeat(0,file_length) However it might be neater to initialize file_proc as {} and change the "file_proc[x]=getc(file_i)" line to: file_proc=file_proc&getc(file_i) Graeme. ----------------------------------------------------