BBC BASIC for Windows
Programming >> Database and Files >> Reading Files
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1369070349

Reading Files
Post by Matt on May 20th, 2013, 5:19pm

Hi,
After testing, it appears that when reading strings into variables (e.g. INPUT#fn, text$), if the final string in the file does not contain a CR (CHR$13) at the end, it will not read it (or will ignore it). If this is the case (and I'm not just making a mistake), is there any way to overcome this? The file I'm reading from may not be created from a BB4W program, therefore no guarantee can be made that the file will end with a CR.
Matt

Ignore this. Brain's not working. Answer's staring me in the face in Help.
Re: Reading Files
Post by admin on May 20th, 2013, 10:06pm

on May 20th, 2013, 5:19pm, Matt wrote:
The file I'm reading from may not be created from a BB4W program, therefore no guarantee can be made that the file will end with a CR.

INPUT# is primarily intended to read data which was written using PRINT#. That is particularly true of numeric data, which is stored by BBC BASIC in a 'private' binary format in order to preserve accuracy.

If you want to read data from a file which was not originally written using PRINT# then GET$# is often a better choice. GET$# accepts a wider range of delimiters (CR, LF or NUL) and if the final data item in the file is not terminated it will still be returned.

So, to store data in a file so that it can later be retrieved by the same, or another, BB4W program, use PRINT# and INPUT#. To read data written by a different program, use GET$# for textual data and BGET# for binary data.

Richard.
Re: Reading Files
Post by Matt on May 21st, 2013, 05:19am

Thanks Richard.

I thought I knew INPUT# so didn't really take in what the Help was saying or its alternatives. Serves me right for not paying attention.

Matt