Fread, Fseek – Argox PA-20 Programming Guide User Manual
Page 54
PT-20 Programming Guide
52
w+
Creates a file and opens it for both reading and writing.
If file exists, current contents are destroyed.
Returns: If the file is opened successfully, _fopen returns a pointer to the file. Actually,
this is a pointer to a structure of type _TFILE, which is defined in the header
file. The actual structure is allocated elsewhere and you do not have to
allocate it. In case of an error, _fopen returns a NULL.
Purpose: Use _fread to read a specified number of data items, eachof a given size,
from the current position in a file opened for buffered input. The current
position is updated after the read.
Syntax: size_t _fread(const void *buffer, size_t size, size_t count, _TFILE
*file_pointer);
Example call: Numread = _fread(buffer, sizeof(char), 80, infile);
Includes:
#include “SDK.h”
Description: The fread function reads count data items, each of size bytes, starting at the
current read position of the file specified by the argument file_pointer. After
the read is complete, the current position is updated. You must allocate
storage for a buffer to hold the number of bytes that you expect to read. This
buffer is a pointer to a void data type.
Returns: The _fread function returns the number of items it successfully read.
Purpose: Use _fseek to move to a new position in a file opened for buffered
input/output.
Syntax: int _fseek(_TFILE *file_pointer, long offset, int origin);
Example call: _fseek(infile, 0, SEEK_SET); /* Go to the beginning */
Includes:
#include “SDK.h”
Description: The fseek function sets the current read or write position of the file specified
by the argument file_pointer to a new value indicated by the arguments
“off-set” and “origin”. The
“offset” is a long integer indicating how far away the new position is from a
specific location given in “origin”. The following table explains the possible
value of “origin”.
Origin
Interpretation
SEEK_SET
SEEK_CUR
Beginning of file.
Current position in the file.
Returns: When successful, _fread returns a zero. In case of error, _fread returns a