Help with finding file length

Hey guys.

I have a binary file that I am trying to determine the size of and I produced the following code to do so...

1
2
3
4
5
6
7
8
FILE *file = fopen("binaryBuffer.txt", "r");
    if(file == NULL) return;
    unsigned long long int length = 0;
    int n = 0;
    while(n != EOF){
        n = fgetc(file);
        length++;
    }


The file is not formatted in any way, it is just random and raw data.

I tested the code and it seemed to work however I tested it on quite a few files and I had a file that was 65536 bytes long and this code only detected a length of about 4100.

Does anyone know why this may be?

Regards, Aaron.
Last edited on
Solved it! Opening the file in "rb" (read binary) was the way to go, rather than in "r" (normal read) mode.
Topic archived. No new replies allowed.