Re: Why no post in Stackoverflow.com

new topic     » goto parent     » topic index » view thread      » older message » newer message
rneu said...

I have recently started using OpenEuphoria and I am finding it very interesting. However, I could not find any question on Euphoria or OpenEuphoria on Stackoverflow, which is a very active site for programming related topics. This seemed surprising since OpenEuphoria appears to be very well developed now. I posted a question there but there was no response: https://stackoverflow.com/questions/44353495/reading-a-text-file-line-by-line-in-euphoria . I will be interested to know others' views on this.

from stackoverflow

I am trying to read a simple csv (comma separated text file) using Euphoria langauge:  
#! /usr/bin/eui 
 
include get.e 
 
integer file_id = open("myfile.csv","r") 
if file_id != -1 then 
    sequence input_data = gets(file_id) 
    while sequence(input_data) do 
        printf(1, "The string read is: %s", {input_data}) 
        input_data = gets(file_id) 
    end while 
end if 
printf(1, "before closing..\n") 
close(file_id) 
printf(1, "after closing..\n") 
 

However, it end with error at the end of the file and never reaches "before closing" statement. type_check failure, input_data is -1

How can I make this detect end of the file so as to end the program normally? I tried checking documentation but could not find it.


Problems in Euphoria simplify down to atom and sequence; if you need both then use the object data-type.

Therefore you want

object input_data = gets(file_id) 

The result is when a line of code is read you are reading a sequence of values. At the end of file the return is an atom, which you use to end the input loop.

If you use the object declaration you can use both data-types at the same time.

You "could" use object for every variable and you program will run. However, it is easier to read code when it is divided into atom and sequence. You can even declare your own data-types based on the default data-types.


The easy way to read a text file is:

include std/io.e 
 
fh = open ( " my_file.txt " , "r" ) 
data = read_file ( fh ) 
close ( fh ) 
 
 
-- data contains the entire contents of ## my_file.txt ## 
 
-- there is also write_file 
 

If you have problems use this Forum. If you don't like the documentation complain to me directly. In the world of Euphoria, RTFM means "redact the fine manual", if it doesn't work we will fix it.


They say: "Stack Overflow has 7.3 million programmers."

I guess they need more programmers!

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu