Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Thursday, 4 April 2019

ftell

FTELL Function


The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.


Syntax

The syntax for the ftell function in the C Language is:
long int ftell(FILE *stream);

Parameters or Arguments

stream
The stream whose file position indicator is to be returned.

Returns

The ftell function returns the current file position indicator for stream. If an error occurs, the ftell function will return -1L and update errno.

Required Header

In the C Language, the required header for the ftell function is:
#include <stdio.h>


C program:

#include <stdio.h>

int main(void)
{
    FILE *stream;
    stream = fopen("MYFILE.TXT", "w+");
    fprintf(stream, "This is a test");
    printf("The file pointer is at byte %ld\n", ftell(stream));
    fclose(stream);
    return 0;
}

Output:
The file pointer is at byte 14

0 comments:

Post a Comment