First let's create a 30 bytes long file.
I'm using a shell command to create it :
echo -n -e $(printf "\x86%.0s" {1..30}) > bytefile
stat bytefile
stat --format="%s bytes" bytefile
The output is as following :
File: bytefile
Size: 30 Blocks: 8 IO Block: 4096 regular file
[...]
30 bytes
I'll use a slighty modified version of your code (I've just removed unusued parts for the tests) :
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
FILE* file = fopen(argv[1], "rb");
fseek(file, 0, SEEK_END);
int fileLen=ftell(file);
printf("%ld\n", fileLen);
fclose(file);
}
And its output is about 30 bytes, with no compilation warnings.
It seems that your code doesn't any error, and is doing the job correcty. Your issue can comes from the way you are measuring the file size, the environment of executing the program, or just that the file you're trying with is just the wrong one.
Could you try to use a builtin method to compute the size ? Following the code from here, I've made this snippet (which give me the same result as before) :
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv) {
FILE* file = fopen(argv[1], "rb");
int fileLen, fd;
struct stat buff;
fseek(file, 0, SEEK_END);
fileLen=ftell(file);
printf("%ld\n", fileLen);
// New method, with fstat.
fd = fileno(file);
fstat(fd, &buff);
off_t size = buff.st_size;
printf("%ld\n", size);
fclose(file);
}
If you still got issues after reviewing all of that could you please give a little more details on the workflow you have ? What type of file are you using, the environment your writing and reading in etc.