| 
 
| 
|  Author | Topic: Reading Files  (Read 718 times) |  |  
| 
| 
| Matt Developer
 
 member is offline
 
  
 
 
 
 
  
 Gender:
  Posts: 210
 
 | 
|  | Reading Files « Thread started 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.
 |  
| 
| « Last Edit: May 20th, 2013, 7:14pm by Matt » |  Logged |  
 |  |  |  
| 
| 
| admin Administrator
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 1145
 
 | 
|  | Re: Reading Files « Reply #1 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.
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| Matt Developer
 
 member is offline
 
  
 
 
 
 
  
 Gender:
  Posts: 210
 
 | 
|  | Re: Reading Files « Reply #2 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
 |  
| 
|  |  Logged |  
 |  |  |  
 |