Re: Sequence Building
- Posted by Kasey <kaeyb at GEOCITIES.COM> Apr 27, 1998
- 529 views
Joe Phillips wrote: > > I know I am asking a simple question, but I am spending too much time > testing this. I need to read from a file, delimited by commas, and place > into sequence of sequences. > > That is > > field 1,field 2,field 3,field 4 > > would result in > > line = {{field 1},{field 2},{field 3},{field 4}} > > I am getting confused when I start with > > line = {} > > do I append, use &, or what ? I am reading with getc, so I have to & some > and append some. But, I am not able to keep it straight. Any clarification > available? > > Should I start with > > line = {{},{},{},{}} > > It is much easier to process. But ,this is so restrictive as to number of > fields to read! I am clear on the input procedure. The problem exists > whether I use gets or getc, I still have to parse the line. > > ( BTW, I won't stop using my signature based on the recent rash of flames. > Actually, the analogy is quite appropriate. If you want me off the list, > please indicate that as non-profanely as you can. ) > > + > | > / \ > / \ Rev. Joe Phillips, Pastor > |SBC| Mambrino Baptist Church 817-573-4901 > | | Granbury, Texas hmmm, just off the top of my head:(gotta go to work in a few minutess so this gonna be rough, it does seem to work though) ----------begin code snipet----------------------- function read_file(sequence filename) atom a,fn sequence one,two fn = open (filename,"r")--- open the file for reading if fn = -1 then printf(1,"cant open %s!",{filename}) abort(2) end if a=0 one={} two={} while a != -1 do --- want the whole file one={} while (a !=',') and (a!=-1) and (a!='\n')do --- look for our delimiter,eof and \n a = getc(fn) one = one&a --- add to current element end while if a!=-1 then a = 0 end if two = append(two,one)--- add element to full sequence end while return two end function -----------------------endcode snipet----------------------- this will should also treat \n as a delemiter (like the ',') hope it helps. kasey