Why does this code read all ' ' for the anything after the 4th character?
Posted
by djs22
on Stack Overflow
See other posts from Stack Overflow
or by djs22
Published on 2010-04-07T01:53:20Z
Indexed on
2010/04/07
2:03 UTC
Read the original article
Hit count: 295
#define fileSize 100000
int main(int argc, char *argv[]){
char *name=argv[1];
char ret[fileSize];
FILE *fl = fopen(name, "rb");
fseek(fl, 0, SEEK_END);
long len = fileSize;
fseek(fl, 0, SEEK_SET);
//fread(ret, 1, len, fl);
int i;
*(ret+fileSize) = '\0';
for (i=0; i<fileSize; i++){
*(ret+i)=fgetc(fl);
printf("byte : %s \n", ret);
}
fclose(fl);
}
In the above code, when I feed the name of a jpeg file, it reads anything after the 4th character as ' '...any ideas? Thanks!
© Stack Overflow or respective owner