1. Loopey

I can't get my while to stop doing. Using puts() I found out length isn't
returning 1 then 2 then 3 but ASCII 1 2 3 so l never = > 79. Why? Here's
Some of the code. Am I just stupid?

include file.e
integer fn, fn2, a, c, l -- infile.text, outfile
sequence inLine  -- Store text from infile.txt after procesing
sequence outLine
inLine = {}
OutLine = {}

fn = open("infile.txt", "r")  -- open input file
 if fn = -1 then
    puts(1, "couldn't open infile\n")
 elsif fn != -1 then
    puts(1, "infile opened\n")
end if

fn2 = open("outfile.txt", "w") -- open output file
 if fn2 = -1 then
   puts(1, "couldn't open outfile\n")
 elsif fn2 != -1 then
   puts(1, "outfile opened. \n")
 end if

procedure grab_c()
   c = getc(fn)
end procedure

procedure fst_chk()
 if c = '>' then
   grab_c
 end if
end procedure

while l < 79 do
    fst_chk
    inLine = append(inLine, c)
    l = length(inLine)
    puts(1, l)
end while

Check out my photo album
http://photos.yahoo.com/alvin_ka9qlq

new topic     » topic index » view message » categorize

2. Re: Loopey

------=_NextPart_000_0042_01C0646A.061DC860
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

I think perhaps a "for" loop would be sufficient and less code.

 eg.

 fn =3D open(file_name , "r")
 file =3D get(fn)
 for x =3D 1 to length(file)
     mychar =3D find('<', file)
     seq =3D append(seq,  file[mychar..mychar+79])
     x =3D mychar + 1
 end for

 BEWARE : UNTESTED CODE
 euman at bellsouth.net




------=_NextPart_000_0042_01C0646A.061DC860
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello,<BR><BR>I think perhaps a "for" =
loop would be=20
sufficient and less code.<BR><BR>&nbsp;eg.<BR><BR>&nbsp;fn =3D =
open(file_name ,=20
"r")<BR>&nbsp;file =3D get(fn)<BR>&nbsp;for x =3D 1 to=20
length(file)<BR>&nbsp;&nbsp;&nbsp;&nbsp; mychar =3D find('&lt;',=20
file)<BR>&nbsp;&nbsp;&nbsp;&nbsp; seq =3D append(seq,&nbsp;=20
file[mychar..mychar+79])<BR>&nbsp;&nbsp;&nbsp;&nbsp; x =3D mychar + =
1<BR>&nbsp;end=20
for<BR><BR>&nbsp;BEWARE : UNTESTED CODE<BR>&nbsp;<A=20

------=_NextPart_000_0042_01C0646A.061DC860--

new topic     » goto parent     » topic index » view message » categorize

3. Re: Loopey

Thanks for the fast responds everybody. Right now I'm learning by taking
stuff from the refman and playing with stuff to understand what and how it
works, like length(). When I don't "get" something I rely on all of you to
help explain what I'm missing. You might compare it to being a kindergartner
hanging out with highscool and college people. Some things I get, most I
don't. That's why I have such a hard time debugging. With that in mind,


Brian, sorry I should have included more info. Yes I'm playing with test
loops using length() to  read a series of characters (less the > you get in
forwards) in to a sequence until it gets 80 characters long then add a
return and pass it to another sequence until the end of file when it will
save it to an out file. I know there are better ways but I'm just trying to
see what a given library routine will do, and understand how sequences (the
backbone of Euphoria) work. As time goes on I'll know why I should use this
routine to that routine. Kinda like cutting up frogs in school, there's no
purpose to it except to understand how things work.

OtterDad, I "think" where c is makes it global, could be wrong though.

Euman, Thanks but haven't got to pointers yet, but will.

Still don't know why length() doesn't go 1 2 3 4 though :=<[]
Alvin
-- Stripper v1.00
--
-- Stripes the > off forewards
-- Adds a return after 80 carictors for formating

with trace
include file.e
integer fn, fn2, a, c, l, x -- infile.text, outfile
sequence inLine  -- Store text from infile.txt after procesing
sequence outLine -- Store file for dropping into outfile later

outLine = {}

fn = open("infile.txt", "r")  -- open input file
 if fn = -1 then
    puts(1, "couldn't open infile\n")
 elsif fn != -1 then
    puts(1, "infile opened\n")
end if

fn2 = open("outfile.txt", "w") -- open output file
 if fn2 = -1 then
   puts(1, "couldn't open outfile\n")
 elsif fn2 != -1 then
   puts(1, "outfile opened. \n")
 end if

procedure grab_c()
   x = 0
   while x < 1 do
    c = getc(fn)
   if c != '>' then
    x = 1
   end if
end while
end procedure

inLine = {}
l = 0
while l < 79 do
    grab_c
    inLine = append(inLine, c)  -- now this stoped working, why??????
    l = length(inLine)
    puts(1, l)
end while
Check out my photo album
http://photos.yahoo.com/alvin_ka9qlq

new topic     » goto parent     » topic index » view message » categorize

4. Re: Loopey

Is your prodecure grab_c actually pass c?
I look at that and just wonder, since c is load ina aprocedure
it may be local to that procedure, how do you pass a parameter out
of a procedure? return c?
It may working the way you wrote it, I was just wondering..

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu