LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read one line from File

Hello.
 
i will read alwas one line from the file.
Can you give me a comando?
 
Thanks
 
0 Kudos
Message 1 of 5
(3,457 Views)
Just use the ReadLine function. Check the returned value to see the number of bytes that were read from the file.
0 Kudos
Message 2 of 5
(3,454 Views)
Hello,
 
thanks for your answer.
Can you send me the metode how i can detect the end of the file.
In the Errorhandle isn't a message.
 
wolf4124
0 Kudos
Message 3 of 5
(3,449 Views)

Hello,

the function ReadLine returns -2 if the end of the file is reached, and -1 if an error occurred. Here is some piece of code to show you an example:

 filehandle = OpenFile (pathname, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);

 // Check if the file could be opened.
 if (filehandle == -1 && (error = GetFmtIOError())){
  MessagePopup ("Unable to open the file", GetFmtIOErrorString (error)); 
  return 0;
 }

// Get the data from the file.

while ((num_bytes = ReadLine (filehandle, linebuf, MAX_STRING_LEN-1)) >= 0){
  if (num_bytes > 0){
   // Do something with the bytes you read from the file...
  }
 }
 
 // Check if an error occurred while reading from the file.
 if (num_bytes == -1 && (error = GetFmtIOError ()) > 0){
  MessagePopup ("Error while reading from file", GetFmtIOErrorString (error));
  return 0;
 }

Message Edited by Wim S on 10-10-2006 03:22 PM

0 Kudos
Message 4 of 5
(3,446 Views)
Thanks.
 
wolf4124
0 Kudos
Message 5 of 5
(3,440 Views)