Wheel IDE

Online demo »

File, read

File read example

This example shows how to create a file with meta commands and read strings and numbers from the file.

Code

#project "File read example"

#include "lib/modules/standard.whl"
#include "lib/modules/file.whl"

; Declare a file named "fruit.rtf" and add data to it:
#text "fruit.rtf"
#line "1"
#line "Apple"
#line "2"
#line "Orange"
#line "3"
#line "Grape"

proc main()
    number handle = fileOpenRead("fruit.rtf")
    string s
    number i, j

    clearConsole()

    for i = 0 to 2
        ; Read a number from the file and print the number in de console:
        j = fileReadNumber(handle)
        printN(j)

        ; Read a string from the file and print the string in the console:
        fileReadString(handle, s)
        printS(s)
    end
end