Blitz3D+ Command Reference

ReadInt ( stream )

Parameters

stream - a file stream opened for reading, or a TCP stream

Description

Reads a 32-bit integer from a file or stream.

An int occupies 4 bytes, stored least significant byte first, and covers the full range -2147483648 to 2147483647 - the natural choice for scores, coordinates, counts and most binary save data.

Reading past the end of the file returns 0 rather than raising an error, so a file of unknown length is best read under a While Not Eof(file) loop.

Pair it with WriteInt: values come back exactly as they were written, in the order they were written.

See also: WriteInt, ReadShort, ReadFloat, Eof.

Example

; ReadInt Example
; ---------------

; Save some integers so there is something to read
file=WriteFile("demo_ints.dat")
WriteInt file,10
WriteInt file,-365
WriteInt file,2147483647
CloseFile file

; ReadInt reads a 4-byte integer (-2147483648 to 2147483647)
file=ReadFile("demo_ints.dat")
a=ReadInt(file)
b=ReadInt(file)
c=ReadInt(file)
CloseFile file

Print "Integers read from demo_ints.dat:"
Print "  "+a
Print "  "+b
Print "  "+c

; Clean up the demo file
DeleteFile "demo_ints.dat"
Print "Deleted demo_ints.dat"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index