trying to read strings in a byte at a time...

Blitz3D Forums/Blitz3D Beginners Area/trying to read strings in a byte at a time...

DREAM(Posted 2008) [#1]
;' create a file containing a String
Global f=WriteFile("temp.dat")
WriteCString (f,"This is a test")
CloseFile f

;' Read the file back again
f = ReadFile("temp.dat")
ReadCString(f)
CloseFile f
MouseWait


Function WriteCString(f,txt$)
	DebugLog txt$
	WriteString (f,txt$)
	WriteByte (f,0)
End Function
	
Function ReadCString(f)
	Repeat
		b=ReadByte(f)
		DebugLog b
		If b<>0;Null
			txt$=txt$+Chr(b)
		EndIf
	Until b=0
	Print Chr(txt$)
End Function



i know i can do readstring(file) and writestring(file,string)i am trying to find a way to read a null terminated c string into blitz, and read strings doesn't seem to work.....any ideas...


Snarkbait(Posted 2008) [#2]
You'll have to use WriteByte and do it one byte at a time, writestring prefaces the string with an Int containing the length.


DREAM(Posted 2008) [#3]
ok how do i test for a null character, which is different to the decimal number '0'....isnt it


Snarkbait(Posted 2008) [#4]
no, should be a zero


Wayne(Posted 2008) [#5]
if mystring$=chr$(0) then