gtpc2m3f | C/C++ Language Support User's Guide |
This function gets a current file position.
Format
#include <stdio.h> long int ftell(FILE *stream);
This function obtains the current value of the file position indicator for the stream pointed to by stream.
Normal Return
If successful, the ftell function returns the relative byte offset from the beginning of the file.
Error Return
If unsuccessful, the ftell function returns -1 and sets errno to a positive value.
Programming Considerations
None.
Examples
The following example opens a myfile.dat file for reading. The current file pointer position is stored in variable pos.
#include <stdio.h> int main(void) { FILE *stream long int pos; stream = fopen("myfile.dat", "rb"); /* The value returned by ftell can be used by fseek() to set the file pointer if 'pos' is not -1 */ if ((pos = ftell(stream)) != EOF) printf("Current position of file pointer found\n"); fclose(stream); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.