12-09-2005 03:44 AM
12-09-2005 04:06 AM
The error you are receiving means that you have dimensioned a too little array for the file you are reading. How have you dimensioned the array? Raising its size should easily solve your problems.
As far as I can understand the inner loop is used to read the file contents discarding the end-of-line character: you could also accomplish it by using OpenFile and ReadLine instead of fopen and fget(x): in my opinion these functions are of much easy use and ReadLine automatically discards end-of-line character(s).
12-09-2005 04:49 AM
12-11-2005 10:41 PM - edited 12-11-2005 10:41 PM
Message Edited by vava on 12-11-2005 11:25 PM
12-12-2005 12:20 AM
12-12-2005 01:27 AM
Hello vava.
Roberto is correct; you should find it much easier to do what you want using the OpenFile() and ReadLine() functions.
You could try something like this (assuming the file is already open):
bytesRead = ReadLine (handle, buffer, 255);
while (bytesRead >= 0) // no error (-1), not end-of-file (-2)
{
linesRead++;
if (bytesRead > 0) // non-blank line
{
// Process the current line
// Try the Scan() function; see the CVI help for examples
...
}
bytesRead = ReadLine (handle, buffer, 255);
}
If you want to make a copy of a file, you could try the CVI function CopyFile().
Regards,
Colin.
12-12-2005 01:49 AM
Hello Collins,
Thank u.Can I read the whole file using the loop that u have specified.Can u givea brief explanation of it.If so I can understand it very well.
Vava.
12-12-2005 04:32 PM
"Can I read the whole file using the loop that u have specified"
Yes, you can. The code I posted will do precisely that (with the addition of OpenFile() and CloseFile() calls outside the loop). ReadLine() returns a non-negative value until end-of-file or an error occurs. You can call Scan() within the loop to parse each line of the file.
[I apologise if you already know the following]
CVI has comprehensive Help and Context Menu systems; you really should become familiar with them. You access Help by pressing the F1 key; you call up the context menu by a right-mouse-click on the item of interest. Alternatively, you can use the Help menu at the top of the main CVI window. For example:
If you look at the attached image, you will see the type of information that is available.
Regards,
Colin.
12-13-2005 12:51 AM