Unable to read certain characters (Program Bug and Problems)

by Andrew360 @, Saturday, November 03, 2012, 13:56 (1668 days ago)

Some characters aren't included in Basic's read and readline command. If you add an optional boolean to their code (e.g. read(true)) that specifies if all characters are read, then it would be easier to use binary read. Or, just make a new function like chrread, that would return only one 8-bit character of a file.

This program shows the characters that don't work:

graphvisible 0
outputvisible 1
for i=0 to 255
open "randomfile"
write chr(300)+chr(i)+chr(300)
a$=read+read+read+read
if asc(mid(a$,2,1))=300 then print "Character "+i+" doesn't work for read."
close
kill "randomfile"
next i
print ""
for i=0 to 255
open "randomfile"
write chr(300)+chr(i)+chr(300)
a$=readline+readline+readline+readline
if asc(mid(a$,2,1))=300 then print "Character "+i+" doesn't work for readline."
close
kill "randomfile"
next i

Unable to read certain characters

by Jim ⌂ @, Russell, KY, Sunday, November 04, 2012, 02:21 (1668 days ago) @ Andrew360

Andrew,

The read command and readline command are only designed to work with text strings. If you want to read and write special characters then I would recommend code like:

b$ = "testsuite_binary.dat"
print "new file"
openb b$
for t = 0 to 255
writebyte t
next t
close
openb b$
a = 0
while not eof
a+= readbyte()
end while
call n("bindata sum", a, 32640)
print "position to 10 and read"
seek 10
a=0
while not eof
a+= readbyte()
end while
call n("bindata sum from 10", a, 32595)
close
kill b$

Use openb to turn off crlf translation and use readbyte/writebyte to manipulate the file 8 bits at a time. This is in the binary release 0.9.9.14 and after

Jim

RSS Feed of thread
powered by my little forum