Table of Contents

fwrite

Description

Write an object to a file.

Function prototype

bool fwrite <voidptr:hFile> <varref:Data>

Arguments

Name Type Comment
hFile voidptr A handle to a file created by fopen or fopen_s.
Data varref A reference to an initialised variable, the value of which is to be written to the file. The type of the variable determines the number of bytes to be written.

Return value

True if success, false otherwise.

Example

//
// ask user for filename
//

string FileName
set FileName <zs:file.SaveDlg "txt" NULL "Text files (*.txt)|*.txt|All files (*.*)|*.*|">
if <zs:iseq 0 <zs:strlen FileName>>
  return 0
endif

//
// Ask user for text to write to file
//

string s
if <zs:not <zs:EditUI s "Enter file text">>
  return 0
endif

//
// Open file
//

voidptr fp
assert <zs:fopen_s fp FileName "w"> "Cannot open file!"

//
// Write text to file using fwrite
//

fwrite fp s

//
// Close file
//

fclose fp
  

Comments

None.

See also