8 fileio.ct

Contents of this section

This section describes functions from file fileio.ct.

8.1 fclose

[] = fclose(fnum)
 fclose(fnum) closes file with given identification number.
   The fnum must have been previously obtained from fopen.
See also:
fopen , fformat .
   Error codes:
   -1: Bad argument: not integer
   -2: Bad argument: outside range
   3: File was not open

8.2 fformat

[] = fformat(fnum,str...)
 fformat(fnum,"format-string",arg1,arg2,...) is similar to format,
   except that it does not output to stdout but to opened file.
See also:
format , sformat , fopen .
   Error codes:
   -1: First argument not integer
   -2: First argument not a valid file number
   -3: Second argument not a string or char
   4: File is not open
   

8.3 fopen

[fnum] = fopen(name,mode)
 fopen("filename",mode) opens a file and returns
   its identifier (integer). The mode parameter can be
   "r" or "w" for reading and writing, respectively.
   If the open is not succesful, -1 is returned.
See also:
fformat , fclose .
   Error codes:
   -1: First arg not a string
   -2: Second arg not a string
   -3: Too many open files
   -4: Bad string for second arg

8.4 format

[] = format(str...)
 format("format-string",arg1,arg2,...) prints "format-string"
   to standard output, replacing occurrences of `format-spec`
   with consecutive args. `Format-spec` is either empty, i.e. ``,
   or of the form

       `[-]w[.d]`.

   Here w is the field width (unsigned integer) and d is the number
   of significant digits, also unsigned integer. By default the
   argument is printed left-justified, but the optional minus sign
   dictates right justification. The backquote character `  can be
   produced by writing it three times: ```.
   
   Hint: You can add any number of spaces before the closing backquote,
   for example `20.7    `.
   These spaces do not affect the output. This feature can be used
   to justify source code lines.
See also:
fformat , sformat .
   Error codes:
   1: First argument not a string or char 

8.5 fprintf

[] = fprintf(fnum,formatstr...)
 fprintf(fnum,"format-string",arg1,arg2,...) is an interface to the C
   fprintf function. The format string should have a percent slot
   for every arg. The args may be integer or real scalars or strings.
   The file identifier fnum must have been obtained from fopen.

   Notice: The stream is not flushed after every fprintf operation,
   but a flush occurs whenever you switch from using fprintf to
   fformat on the same file. Therefore avoid mixing fprintf and fformat
   on the same file if performance is an issue for you!
   
See also:
fopen , printf , sprintf , format .
   Error codes:
   1: Bad argument type
   2: Second arg not a string
   3: First argument not an integer
   4: Bad file identifier: out of range
   5: File is not open
   6: Internal error: fdopen failed
   

8.6 printf

[] = printf(formatstr...)
 printf("format-string",arg1,arg2,...) is an interface to the C
   printf function. The format string should have a percent slot
   for every arg. The args may be integer or real scalars or strings.
See also:
fprintf , sprintf , format .
   Error codes:
   1: Bad argument type
   2: First arg not a string
   

8.7 sformat

[s] = sformat(formatstr...)
 sformat("format-string",arg1,arg2,...) is similar to format,
   except that it does not output to stdout but returns a string
   variable.
See also:
format , fformat , sprintf .
   Error codes:
   -1: First argument not a string or char 

8.8 sprintf

[s] = sprintf(formatstr,arg)
 sprintf("format-string",arg1,arg2,...) is an interface to the C
   sprintf function. The format string should have a percent
   slot for every arg. The args may be integer or real scalars
   or strings.
See also:
sformat .

   LIMITATIONS:
       This implementation allows only one arg (arg1).
       The resulting string may not become larger than
           500 chars or Tela may crash.
   Error codes:
   -1: First arg not a string
   -2: Args may only be scalar ints or reals, or strings
   

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter