Read vs Readline

BlitzPlus Forums/BlitzPlus Beginners Area/Read vs Readline

methodman3000(Posted 2013) [#1]
I am working with Doug Cooper's "Oh Pascal book " and translating the excercises into Blitz+ Do read and readline work the same as in Pascal?

I am not understanding this excercise after repeated attempt
Statement Last value read value about to be read
1 Read(C1) A B
2. read (c1); B C
3 read (C1), (C2), (C3);
4 Read (C1), (C2), (C3), (C4), (C5); E blank( screen)
5 REad (C1), (C2), (C3), (C4), (C5), (C6) blank Start of new line
6Read; illegal read must actually get values
7 Readline none start of next line
8 readline(C1); A start of next line
9 readline (C1),(C2), (C3); C start of next line
10 readline (C1), (C2), (C3), (C4), (C5) E start of next line.
I am not following this if I correspond say the occurance of verticle lines doesn't seem to correspond to the verticle positions. Read line is supposed to keep intact the carrage returns. Doe this match Blitz or is it very different? I don't understand what this is trying to convey Help?


Yasha(Posted 2013) [#2]
I don't know Pascal so couldn't say too much, but Read and ReadLine are completely unrelated commands in Blitz.

-- ReadLine reads a line of text from an open file handle or network stream, stopping when it reaches the CRLF line terminator or the end of the stream. It returns a string with the given text data. The string does not include the line terminator.

-- Read is a legacy command (i.e. not really recommended for general use) that reads values from a built-in hardcoded data table in your program (the kind of table you construct with Data statements). It is a special syntax form, so rather than accepting an argument value and returning a function, it accepts a variable name to 'put the next data item into', where 'next item' is a hidden, automatically-incrementing index into the data table. This syntax is totally different from anything else in the language.

'Read' is a traditional feature dating all the way back to the original BASICs of the 1960s, so I very much doubt it's what you want in this case.


Floyd(Posted 2013) [#3]
According to my fading memories of Pascal ReadLn is the same as Blitz's ReadLine.
It is used for text files, with each line terminated by an "end of line" marker. In Windows that is actually two characters: Carriage Return and Line Feed. One entire line of text is read, then the file pointer moves past the end of line marker and is ready to continue reading.

Pascal's Read would normally be used for numeric data. It would read one value. There is no end of line, so the file pointer is positioned immediately after what was just read.
Blitz has different file reading commands for different types of numbers: ReadFloat, ReadInt, ReadShort and ReadByte.

As mentioned, Blitz's Read command has nothing at all to do with files. It is used with Data statements.