FILE_LEN.C

LIB3/SECURE/SIMUL_EF/FILE_LEN.C · 557 B

From the archive nm4dos.zip

Download the archive   « Back to the archive contents

/*
 * returns the number of lines in a file.
 */
int     file_length( string file_name )
{
    int     top, bottom;

    if( (top = file_size( file_name )) < 0 )
	return top;
    top = top / 46;
    if( top < 2 )
	top = 2;
    bottom = 1;
    while( read_file( file_name, top ) )
    {
	top = top + top / 2;	/* top *= 1.5; */
    }
    while( top > bottom + 1 )
    {
	if( read_file( file_name, ( top + bottom ) / 2 ) )
	{
	    bottom = (top + bottom) / 2;
	}
	else
	{
	    top = (top + bottom) / 2;
	}
    }
    return bottom - 1;
}				/* file_length() */

Site Stats

Snippets: 1791
Codebases: 571