1. Printing numbers
- Posted by Sid Sidebottom <sid.sidebottom at ST.COM> Nov 20, 2000
- 403 views
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
2. Re: Printing numbers
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Nov 20, 2000
- 398 views
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
3. Re: Printing numbers
- Posted by David Cuny <dcuny at LANSET.COM> Nov 20, 2000
- 387 views
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
4. Re: Printing numbers
- Posted by cense <cense at mail.ru> Nov 20, 2000
- 413 views
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]
5. Re: Printing numbers
- Posted by Derek Parnell <derekp at solace.com.au> Nov 21, 2000
- 389 views
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