(octave.info)Line-Oriented Input


Next: Formatted Output Prev: Simple Output Up: C-Style I/O Functions
Enter node , (file) or (file)node

14.2.3 Line-Oriented Input
--------------------------

To read from a file it must be opened for reading using ‘fopen’.  Then a
line can be read from the file using ‘fgetl’ as the following code
illustrates

     fid = fopen ("free.txt");
     txt = fgetl (fid)
          ⊣ Free Software is needed for Free Science
     fclose (fid);

This of course assumes that the file ‘free.txt’ exists and contains the
line ‘Free Software is needed for Free Science’.

 -- : STR = fgetl (FID)
 -- : STR = fgetl (FID, LEN)
     Read characters from a file, stopping after a newline, or EOF, or
     LEN characters have been read.

     The characters read, excluding the possible trailing newline, are
     returned as a string.

     If LEN is omitted, ‘fgetl’ reads until the next newline character.

     If there are no more characters to read, ‘fgetl’ returns −1.

     To read a line and return the terminating newline see ‘fgets’.

     See also: Note: fgets, Note: fscanf, Note:
     fread, Note: fopen.

 -- : STR = fgets (FID)
 -- : STR = fgets (FID, LEN)
     Read characters from a file, stopping after a newline, or EOF, or
     LEN characters have been read.

     The characters read, including the possible trailing newline, are
     returned as a string.

     If LEN is omitted, ‘fgets’ reads until the next newline character.

     If there are no more characters to read, ‘fgets’ returns −1.

     To read a line and discard the terminating newline see ‘fgetl’.

     See also: Note: fputs, Note: fgetl, Note:
     fscanf, Note: fread, Note: fopen.

 -- : NLINES = fskipl (FID)
 -- : NLINES = fskipl (FID, COUNT)
 -- : NLINES = fskipl (FID, Inf)
     Read and skip COUNT lines from the file specified by the file
     descriptor FID.

     ‘fskipl’ discards characters until an end-of-line is encountered
     exactly COUNT-times, or until the end-of-file marker is found.

     If COUNT is omitted, it defaults to 1.  COUNT may also be ‘Inf’, in
     which case lines are skipped until the end of the file.  This form
     is suitable for counting the number of lines in a file.

     Returns the number of lines skipped (end-of-line sequences
     encountered).

     See also: Note: fgetl, Note: fgets, Note:
     fscanf, Note: fopen.


automatically generated by info2www version 1.2.2.9