L3DT users' wiki
Large 3D terrain generator

fgetc

Description

Read a single character from a file at the current stream position.

Function prototype

int fgetc <voidptr:hFile>

Arguments

Name Type Comment
hFile voidptr A handle to a file created by fopen or fopen_s.

Return value

The value of the character in the file at the current stream position, or EOF (-1) if an error occurred.

Example

// 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
set c 0
string s

// Read file character-by-character using fgetc, and add to string

do
  set c <fgetc fp>
  if <isgt c 0>
    set s <strcat s c>
  endif
while <isgt c 0>

echo s // Write file contents (in string) to event log

fclose fp // Close file

Comments

None.

See also

 
plugins/general/zeoscript/reference/functions/fgetc.txt · Last modified: 2017/08/31 05:24 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki