Programming Reference/Librarys
Question & Answer
Q&A is closed
#include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ int main( void ) { FILE *stream; int c; if((stream=fopen("test.txt","r"))==NULL) { printf("Cannot open file.\n"); return 1; } while((c = fgetc(stream) ) != EOF) { printf("position of pointer in the stream is %i on character %c\n", ftell(stream), c); } fclose(stream); return 0; }
Test 1234
output: ./ftell position of pointer in the stream is 1 on character T position of pointer in the stream is 2 on character E position of pointer in the stream is 3 on character s position of pointer in the stream is 4 on character t position of pointer in the stream is 5 on character position of pointer in the stream is 6 on character 1 position of pointer in the stream is 7 on character 2 position of pointer in the stream is 8 on character 3 position of pointer in the stream is 9 on character 4