Description | An example script demonstrating how to use the fopen, fread and fclose script functions. |
---|---|
Author | Aaron |
Created | 2010/05/24 |
Requires | L3DT v2.9 beta 2 or later |
Download | fread test.zs |
// // Ask user for filename // string FileName set FileName <file.OpenDlg "txt" NULL "Text files (*.txt)|*.txt|All files (*.*)|*.*|"> if <iseq 0 <strlen FileName>> return 0 endif // // Open file // voidptr fp set fp <fopen FileName "r"> assert fp "Cannot open file!" // // Prepare some variables // char c string s bool FileDone set FileDone false // // Read file character-by-character, and add to string // do if <fread fp c> set s <strcat s c> else set FileDone true endif while <not FileDone> // // Write file contents (in string) to event log // echo s // // Report file length using ftell // echo <strcat <strcat "File length was " <ftell fp>> " bytes"> // // Close file // fclose fp
None.