About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/fgetslines.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 fgetslines Context: slangrtl

Synopsis

Read all the lines from an open file

Syntax

String_Type[] fgetslines (File_Type fp)

Description

The fgetslines function returns all the remaining lines as an array of strings in the file specified by the open file pointer fp. If the file is empty, an empty string array will be returned. The function returns NULL upon error.

Example

The following function returns the number of lines in a file:

    define count_lines_in_file (file)
    {
       variable fp, lines;

       fp = fopen (file, "r");
       if (fp == NULL)
         return -1;

       lines = fgetslines (fp);
       if (lines == NULL)
         return -1;

       return length (lines);
    }

Note that the file was implicitly closed by the function.

This function should not be used if the file contains many lines since that would require that all the lines be read into memory.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.