Read all the lines from an open file
String_Type[] fgetslines (File_Type fp)
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.
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.
- slangrtl
-
clearerr,
fclose,
fdopen,
feof,
ferror,
fflush,
fgets,
fileno,
fopen,
fputs,
fread,
fseek,
ftell,
fwrite,
isatty,
mkdir,
open,
popen,
read
|