LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

get number of lines of a text file

Hi,
Id like to read a text file in which are stored parameters in cloumns and I like to stop before unwritten values because unwritten values are not empty but returns random numbers.
is there a function that return the number of lines of a text file.
or is there a way to create that kind of function.
thanks

Olivier
0 Kudos
Message 1 of 2
(3,729 Views)

 int  i, line;
 int  fH = 0, cnt = 0, ioerr = 0;
 char msg[512], file[MAX_PATHNAME_LEN];

 // 'file' must contain the file pathname
 fH = OpenFile (file, VAL_READ_ONLY, VAL_APPEND, VAL_ASCII);
 while (TRUE) {
  // Count rows
  ioerr = ReadLine (fH, msg, -1);
  if (ioerr == -2) break; // End of file
  if (ioerr == -1) {  // I/O Error
   line = __LINE__; ioerr = GetFmtIOError (); goto Error;
  }
  cnt++;
 }
 SetFilePtr (fH, 0, 0);  // Return to beginning of file



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 2
(3,722 Views)