File Input/Output Functions

Access to any kind of file can be useful to analyze data which come from other applications (such as experimental data) and to generate results in a form suitable for other applications (such as source code or HTML files). Functions specific to files are described in this section. Input, output, and control are done with the following generic functions:

FunctionDescription
fcloseclose the file
feofcheck end of file status
fflushflush I/O buffers
fgetlread a line
fgetsread a line
fprintfwrite formatted data
freadread data
fscanfread formatted data
fseekchange the current I/O position
ftellget the current I/O position
fwritewrite data
redirectredirect output

fopen

Open a file.

Syntax

fd = fopen(path)
fd = fopen(path, mode)

Description

fopen opens a file for reading and/or writing. The first argument is a path whose format depends on the platform. If it is a plain file name, the file is located in the current directory; what "current" means also depends on the operating system. The output argument, a real number, is a file descriptor which can be used by many input/output functions, such as fread, fprintf, or dumpvar.

The optional second input argument, a string of one or two characters, specifies the mode. It can take one of the following values:

ModeMeaning
(none)same as 'r'
'r'read-only, binary mode, seek to beginning
'w'read/write, binary mode, create new file
'a'read/write, binary mode, seek to end
'rt'read-only, text mode, seek to beginning
'wt'read/write, text mode, create new file
'at'read/write, text mode, seek to end

See also

fclose


Copyright 1998-2007, Calerga.
All rights reserved.