A bit of trouble with fread
Hello,
I am having a bit of trouble with fread. It is only reading one character out of a file when I am trying to get it to read 5. fread does return 5, but I still only get one character. Here is my code:
char test[5];
fp=fopen("wa.txt", "rb");
fread(test,1,5,fp);
MessageBox(wmain,test,"Test",MB_OK);
fclose(fp);
The messagebox command only pops up a single character, which is the first character in my file. Would you happen to know what I might be doing wrong? Thank you.
try this homie:
char test[6];
fp=fopen("wa.txt", "rb");
fread(test,1,5,fp);
test[5] = ''\0'';
MessageBox(wmain,test,"Test",MB_OK);
fclose(fp);
char test[6];
fp=fopen("wa.txt", "rb");
fread(test,1,5,fp);
test[5] = ''\0'';
MessageBox(wmain,test,"Test",MB_OK);
fclose(fp);
you are opening binary when it says ''wa.txt'', not sure if it matters, but try it without the ''b'' in "rb". you may have to use getch or something like that instead of fread in text mode
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement