You have misinterpreted the ftell & fseek functions. Less coffee more rest :p
ftell manpage
long ftell(FILE *stream);
The ftell() function obtains the current value of the file position
indicator for the stream pointed to by stream.
fseek manpage
int fseek(FILE *stream, long offset, int whence);
The fseek() function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is
obtained by adding offset bytes to the position spec‐
ified by whence. If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current
position indicator, or end-of-file, respectively. A
successful call to the fseek() function clears the end-of-file indicator for the stream and undoes any effects of the ungetc(3)
function on the same stream.
Create sample.txt
echo -n 'q' > sample.txt
File Seek Example
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char** argv )
{
FILE* file = fopen( "sample.txt", "r" );
if( NULL == file )
{
perror("Failed to open file");
return EXIT_FAILURE;
}
printf("File successfully opened\n");
long position = ftell( file );
printf( "Position before seek: %lu\n", position );
int status = fseek( file, 1L, SEEK_SET );
if( 0 != status )
{
perror("Failed to seek");
return EXIT_FAILURE;
}
printf("File seek successful\n");
position = ftell( file );
printf( "Position after seek: %lu\n", position );
return EXIT_SUCCESS;
}
File Size Example
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
int main( int argc, char** argv )
{
struct stat file_status = { 0 };
int status = stat( "sample.txt", &file_status );
if ( 0 != status )
{
perror("Failed to read file status");
return EXIT_FAILURE;
}
printf( "File size: %li\n", file_status.st_size );
return EXIT_SUCCESS;
}
Build
gcc -o example example.c