| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

get_file_lines

#include "sflfile.h"
long
get_file_lines (
    const char *filename)

Synopsis

Reads an entire file, and returns the number of lines in the file. The file should be normal text. Returns 0 if the file cannot be opened for reading. May be a bit slow on large files.

Source Code - (sflfile.c)

{
    long
        file_size;
    FILE
        *file_stream;
    int
        ch;

    ASSERT (filename);

    file_stream = file open (filename, 'r');
    if (file_stream == NULL)
        return (0);

    file_size = 0;
    while ((ch = fgetc (file_stream)) != EOF)
        if (ch == '\n')
            file_size++;

    fclose (file_stream);
    return (file_size);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation