×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Strage problems with fread and int=13 or 26.

Strage problems with fread and int=13 or 26.

Strage problems with fread and int=13 or 26.

(OP)
When I try to read an integer from a binary file and the integer is either 13 or 26 the programm doesn't read it correctly, otherwise there is no problem. I've checked and edited the file with a hex editor and it is alright. I've tried standard C and similar problems occur. I'm desperate. HELP!

This is a simple version of a function that shows what I mean.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
FILE *in, *out;
int c, rein, raus, dummy;

in=fopen("c:\\test.bin","w");
rein=13; //26;
c=fwrite(&rein, sizeof(int), 1, in);
fclose (in);

out=fopen("c:\\test.bin","r");
c=fread(&raus, sizeof(int), 1, out);
Label1->Caption=rein;
dummy=raus;
Memo1->Lines->Append(dummy);
fclose (out);
}

RE: Strage problems with fread and int=13 or 26.

I think the problem's because u did not open the file in binary mode while reading from it...(try "rb" instead of "r")...

Ankan.

Please do correct me if I am wrong.

RE: Strage problems with fread and int=13 or 26.

Greetinx!

U may replace fwrite and fread methods with fprintf and fscanf methods.

Happy programming!))

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close