|
Table of Contents
freadDescriptionRead an object from a file. Function prototypebool fread <voidptr:hFile> <varref:Data> ArgumentsReturn valueTrue if success, false otherwise. Example//
// Ask user for filename
//
string FileName
set FileName <zs:file.OpenDlg "txt" NULL "Text files (*.txt)|*.txt|All files (*.*)|*.*|">
if <zs:iseq 0 <zs:strlen FileName>>
return 0
endif
//
// Open file
//
voidptr fp
assert <zs:fopen_s fp FileName "r"> "Cannot open file!"
//
// Prepare some variables
//
char c
string s
bool FileDone
set FileDone false
//
// Read file character-by-character using 'fread', and add to string
//
do
if <zs:fread fp c>
set s <zs:strcat s c>
else
set FileDone true
endif
while <zs:not FileDone>
//
// Write file contents (in string) to event log
//
echo s
//
// Report file length using ftell
//
echo <zs:strcat <zs:strcat "File length was " <zs:ftell fp>> " bytes">
//
// Close file
//
fclose fp
… the output of which is written to the event log by echo as: This is the contents of an example text file. File length was 45 bytes CommentsNone. See alsoExcept where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
|