1. How Do You Read A Number From A Text File?

I am OBVIOUSLY a new user of Euphoria, but so far I
love it!  I hate to ask this question, but this is
very hard for me to find out how to do since most of
the user contributed programs don't parse text files.

CAN YOU PLEASE HELP ME DO THE FOLLOWING?

Read a text file that has the folling information in
it. (3 lines...)

10.00
20.00
200.00

And add these three lines in Euphoria to 230.00 and
print this to the screen?

Is there a function that reads from a text file and
makes the value a non sequence or string?  Everytime I
try this i get 1 in the first position 0 in the second
and I can't add them together!!

PLEASE HELP ME  mailto:thetemples at yahoo.com




=====
mailto:thetemples at yahoo.com
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

new topic     » topic index » view message » categorize

2. Re: How Do You Read A Number From A Text File?

From: Temples <thetemples at YAHOO.COM>
Subject: How Do You Read A Number From A Text File?


> I am OBVIOUSLY a new user of Euphoria, but so far I
> love it!  I hate to ask this question, but this is
> very hard for me to find out how to do since most of
> the user contributed programs don't parse text files.
>
> CAN YOU PLEASE HELP ME DO THE FOLLOWING?
>
> Read a text file that has the folling information in
> it. (3 lines...)
>
> 10.00
> 20.00
> 200.00
>
> And add these three lines in Euphoria to 230.00 and
> print this to the screen?
>
> Is there a function that reads from a text file and
> makes the value a non sequence or string?  Everytime I
> try this i get 1 in the first position 0 in the second
> and I can't add them together!!

Below is one way. There are probably others.

include get.e -- required for the get() function
object n  -- storage for the number read in
integer fn -- file handle
atom total -- obvious

total = 0
fn = open("C:\\EUPHORIA\\WIN32LIB\\NUMB.TXT","r")
       -- change the file path to suit

if fn < 1 then puts(1,"Error, cannot open file")
else   -- go into a loop to read numbers from the file
         -- no matter how many numbers there may be

while 1 do
   n = get(fn) -- n will be a sequence of 2 numbers, {result,value}
   if n[1] = GET_EOF then exit
   else total += n[2]
   end if
 end while

printf(1,"The total is: %8.2f",total)
end if

Regards,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu