Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-27 LabWindows/CVI Standard Libraries
Return Value
position long integer Offset of the new file pointer
position from the beginning of
the file.
Return Code
-1 Error due to an invalid file handle, an invalid origin
value, or an offset value that is before the beginning
of the file.
Parameter Discussion
The valid values of origin are as follows:
0 = beginning of file
1 = current position of file pointer
2 = end of file
Using This Function
This function can also be used to obtain the file size by setting offset to 0 and origin to 2. In this
case, the return value indicates the file size and the pointer will be at the end of the file.
It is possible to position the file pointer beyond the end of the file. Intermediate bytes (bytes
between the old end of file and the new end of file) contain indeterminate values. An attempt to
position the file pointer before the beginning of the file causes the function to return an error.
If the file is a device that does not support random access (such as the standard input), the
function returns an indeterminate value.
Example
/* Open or create the file c:\TEST.DAT, move 10 bytes into the
file, and write a string to the file. */
/* Note: Use \\ in pathname in C instead of \. */
int handle,result;
long position;
handle = OpenFile("c:\\TEST.DAT", 0, 2, 1);
if (handle == -1){
FmtOut("error opening file");
exit(1);
}
position = SetFilePtr(handle, 10L, 0);
if (position == 10){