A Windows NT user in the USA has recently reported (October '98) a problem when reading ASCII files using INPUT FILE. He was attempting to read a text file like this:
37 - a count of the text lines to follow 0.0005 U - each line consists of a decimal 0.0005 U - number in ASCII form, a space 0.0005 U - and then a letter 0.02 U : : 0.01 U 0.01 U
using the following code:
OPEN FILE 1,"a:\in-data.txt",READ
INPUT FILE 1: n // Read the count of lines
FOR i:=1 TO n DO
INPUT FILE 1: r,f$ // Read each line, number first then letter
PRINT i;r;f$ // Print a line number, the number data, then the letter
ENDFOR i
CLOSE FILE 1
This program runs perfectly on DOS, Windows 3.1 and Windows 95 (we haven't tested it on Windows 98 yet). When it was run from Windows NT 4.0, however, only 34 lines of the file were read instead of 37. The program then stopped, delivering the error message "201: End of file in line ...."
The cause of this problem is not yet clear. However, it seems to have something to do with the operation of the INPUT FILE command under Windows NT 4.0.
The problem disappears if the program is rewritten, replacing INPUT FILE with the GET$ command. In the following version, GET$ is used to read the characters from the file one at a time. WHILE loops are used, first to read the text characters, appending each in turn to a string variable, then to read and ignore any end-of-line control codes which are present at the end of each text line of the file.
0010 OPEN FILE 1,"A:\in-data.txt",READ 0020 number_of_lines$:="" 0030 character$:=GET$(1,1) // using GET$ to read a single byte 0040 WHILE ORD(character$)>31 DO // up to whatever control code is EOL 0050 number_of_lines$:+character$ 0060 character$:=GET$(1,1) 0070 ENDWHILE 0080 number_of_lines#:=VAL(number_of_lines$) 0090 WHILE ORD(character$)<32 DO character$:=GET$(1,1) // clear any EOL codes 0100 FOR line#:=1 TO number_of_lines# DO 0110 line$:="" 0120 character$:=GET$(1,1) 0130 WHILE ORD(character$)>31 DO 0140 line$:+character$ 0150 character$:=GET$(1,1) 0160 ENDWHILE 0170 PRINT line$ // This should include both the number and the letter 0190 IF line#=number_of_lines# THEN EXIT // Avoids reading EOF 0200 WHILE ORD(character$)<32 DO character$:=GET$(1,1) 0210 ENDFOR line# 0220 CLOSE
We will be having a closer look at this problem as and when we can. Meanwhile, if any users of UniCOMAL V3.11, Developers' or Students' version, on MS-Windows NT, encounter this or any similar problem, we would be glad if they would email the details to support@macharsoft.co.uk.
Posted 13.10.1998