xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FLineCount()

Counts the lines in an ASCII text file.

Syntax

FLineCount( <cFileName> ) --> nLineCount

Arguments

<cFileName>
This is a character string holding the name of the text file whose lines to count. It must include path and file extension. If the path is omitted from <cFileName>, the file is searched in the current directory.

Return

The function returns the number of lines contained in <cFileName> as a numeric value. If the file <cFileName> does not exist or cannot be opened, the return value is zero.

Description

FLineCount() is an optimized function for counting the lines in an ASCII text file fast and efficiently. It can be used in conjunction with HB_FReadLine() to extract single lines from an ASCII text file.

Info

See also:FileStats(), FCharCount(), FCreate(), FOpen(), FParse(), FWordCount(), HB_FReadLine(), MemoLine(), MlCount()
Category: File functions , xHarbour extensions
Source:rtl\fparse.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example uses FLineCount() to determine the size of an
// array used to collect all lines of a text file.

   PROCEDURE Main
      LOCAL cFileName   := "Test.txt"
      LOCAL nCount      := FLineCount( cFileName )
      LOCAL aLines      := Array( nCount )
      LOCAL nFileHandle := FOpen( cFileName )
      LOCAL nLine       := 0
      LOCAL cLine

      FOR EACH cLine IN aLines
         HB_FReadLine( nFileHandle, @cLine )
         aLines[ ++nLine ] := cLine
      END

      FClose( nFileHandle )

      ? Len( aLines )
      AEval( aLines, {|c| QOut( c ) } )
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe