3

I don't understand why i get this strange result by this function with some files.

For example if i have a

input.txt

and inside of it there is a string like

abcd

if i do something like:

FILE* file = fopen("intput.txt", "r"); char currentChar; long n = ftell(file); //return 0 it's ok fread(&currentChar, sizeof(char), 1, file); long n = ftell(file); // return 1 it's ok 

Now if i do the same things but with a (for example) .png file i have different result:

FILE* file = fopen("intput.png", "r"); char currentChar; long n = ftell(file); //return 0 it's ok fread(&currentChar, sizeof(char), 1, file); long n = ftell(file); // return 216 why return 216 and not 1 

I don't understand why with the input.png file i get 216 instead of 1

7
  • 3
    did you check fread result ? Commented Aug 17, 2014 at 17:02
  • 3
    try FILE* file = fopen("intput.png", "rb"); and also long n redefinition. Commented Aug 17, 2014 at 17:08
  • yes in both files it get the first byte Commented Aug 17, 2014 at 17:09
  • 1
    Are you on windows? or unix? Commented Aug 17, 2014 at 17:09
  • im on windows, with the binary reading mode it works, thx Commented Aug 17, 2014 at 17:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.