AnsweredAssumed Answered

fread() reads garbage data when file is open with "rb"

Question asked by zhaosheng.pan on Feb 11, 2018
Latest reply on Mar 13, 2018 by zhaosheng.pan

Hello,

 

I was using ADSP-21489 EZ-Board with CCES 2.7.0 and trying to do some simple file reading with stdio, but I found the data returned by fread() was always garbage, but after I changed the open mode from "rb" to "r", the data was correct.

 

The code was like this:

 

char *buf = malloc(1024);

FILE *f = fopen("file.txt", "rb");

size_t count = fread(buf, 1, 1024, f);

buf[count] = 0;

printf("%ul\n", count);

printf("%s\n", buf);

fclose(f);

 

I also found that no matter how big the file was, the count returned by fread() was always 280. Is there something wrong with my code or my configuration?

 

Thank you for your help.

Outcomes