File Input Output in Euphoria

Published on 16 February 2023 (Updated: 19 February 2023)

Welcome to the File Input Output in Euphoria page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

include std/io.e
include std/types.e

function write_file(sequence filename)
    integer fn = open(filename, "w")
    if fn < 0
    then
        printf(STDERR, "Cannot open %s for write\n", {filename})
        return FALSE
    end if

    puts(fn, "Hello from Euphoria!\n")
    puts(fn, "This is a line\n")
    puts(fn, "This is another line\n")
    puts(fn, "Goodbye!\n")
    close(fn)
    return TRUE
end function

function read_file(sequence filename)
    integer fn = open(filename, "r")
    if fn < 0
        then
        printf(STDERR, "Cannot open %s for read\n", {filename})
        return FALSE
    end if

    object line
    while 1
    do
        line = gets(fn)
        if atom(line)
        then
            exit
        end if

        puts(STDOUT, line)
    end while

    close(fn)
    return TRUE
end function

constant filename = "output.txt"
if write_file(filename)
then
    read_file(filename)
end if

File Input Output in Euphoria was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.