1. Printing numbers

Hi,

OK, I've only been playing with Euphoria for a couple of years, but I have
an elementary question that's driving me nuts.

I want to take a sequence of integers and turn it into a .csv file - ie a
text file with the numbers as numbers, with commas in between (and maybe
semicolons for line delimiters). No braces or anything, just numbers.

I've tried print, puts etc, and a couple of libraries in the archives, but
nothing I do seems to work.

It surely can't be that hard???

Apologies if I'm being really stupid and have missed something blindingly
obvious, but can anyone help?

TIA

Sid

new topic     » topic index » view message » categorize

2. Re: Printing numbers

Sid,

If you use Gabriel Boehme's "print.e" from the archives, it's pretty easy
(and this is why it really should be in Euphoria in the first place):

<code follows>
include print.e
sequence someNumbers
someNumbers = {1,2,3,4}

procedure someProcedure()
integer outFile
outFile = open("num.txt", "w")
for n = 1 to length(someNumbers) do
   print(outFile, someNumbers[n])
   if n < length(someNumbers) then
      puts(outFile, ",")
   end if
end for
close(outFile)
end procedure
<end code>


result is:
1,2,3,4

Dan Moyer


----- Original Message -----
From: "Sid Sidebottom" <sid.sidebottom at ST.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Monday, November 20, 2000 4:48 AM
Subject: Printing numbers


> Hi,
>
> OK, I've only been playing with Euphoria for a couple of years, but I have
> an elementary question that's driving me nuts.
>
> I want to take a sequence of integers and turn it into a .csv file - ie a
> text file with the numbers as numbers, with commas in between (and maybe
> semicolons for line delimiters). No braces or anything, just numbers.
>
> I've tried print, puts etc, and a couple of libraries in the archives, but
> nothing I do seems to work.
>
> It surely can't be that hard???
>
> Apologies if I'm being really stupid and have missed something blindingly
> obvious, but can anyone help?
>
> TIA
>
> Sid

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

3. Re: Printing numbers

Dan Moyer wrote:

> If you use Gabriel Boehme's "print.e"
> from the archives, it's pretty easy...

Not to knock Gabriel's library, but if you change the line:

> print(outFile, someNumbers[n])

into:

> printf(outFile, "%d", {someNumbers[n]})

you should get the same result, without having to use Gabriels's library.

-- David Cuny

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

4. Re: Printing numbers

On Mon, 20 Nov 2000, David Cuny wrote:
>> Dan Moyer wrote:
>> 
>> > If you use Gabriel Boehme's "print.e"
>> > from the archives, it's pretty easy...
>> 
>> Not to knock Gabriel's library, but if you change the line:
>> 
>> > print(outFile, someNumbers[n])
>> 
>> into:
>> 
>> > printf(outFile, "%d", {someNumbers[n]})

i would have always thought that to be the logical way to print decimals
because i came from a C/C++ (not much though) background before euphoria
 
>> you should get the same result, without having to use Gabriels's library.
>> 
>> -- David Cuny



-- 
evil, corruption and bad taste
^[cense]

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

5. Re: Printing numbers

Hi Sid,
>
>I want to take a sequence of integers and turn it into a .csv file - ie a
>text file with the numbers as numbers, with commas in between (and maybe
>semicolons for line delimiters). No braces or anything, just numbers.
>

Here is one way of doing this...

    sequence NumberList
    integer FldDelim, LineDelim, Delim

    FldDelim = ','
    LineDelim = ';'
    for i = 1 to length(NumberList) do
       if i != length(NumberList) then
            Delim = FldDelim
       else
            Delim = LineDelim
       end if
       printf(file, "%d%s", {NumberList[i]), Delim})
    end for

-----
cheers,
Derek Parnell

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

Search



Quick Links

User menu

Not signed in.

Misc Menu