User Tools

Site Tools


c:stdio.h:ftell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:ftell [2013/01/22 22:02] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== ftell =====
 +
 +<code c>
 +    long int ftell(FILE *stream);
 +</code>
 +Returns current file position for stream stream, or -1 on error.
 +
 +
 +===== C Sourcecode Example =====
 +<code c>
 +#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;
 +}
 +</code>
 +
 +=== content of test.txt ===
 +
 +<code c>
 +Test 1234
 +</code>
 +
 +==== output ====
 +    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
  
advertising
c/stdio.h/ftell.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz