Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Chocoboko

A bit of trouble with fread

This topic is 5589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!