Link to home
Start Free TrialLog in
Avatar of srivats123
srivats123

asked on

Integer shift problem

Hi All,

   My problem is If I write an Integer into a file, integer shifts beyond a limit. I get junk values like
-828373764 for some value like 25 or 30 written into the file. Any suggestions. Thanks.I've declared the numbers as unsigned long.
Avatar of Exceter
Exceter
Flag of United States of America image

Could you post the code?
Avatar of srivats123
srivats123

ASKER

struct page
{
     int pointer;
     int no_entries;
     record rec[7];    
};//end struct page

struct record
{
        int key;
        int order;
}

page p;

for(int i=0;i<=6;i++)
{
  p.rec[i].key = some_int_val;
  p.rec[i].order = some_int_val;
}

fseek(fp,valid_position,0);
fwrite(&p,sizeof(page),1,fp);


Now an fread(&p,sizeof(page),1,fp) returns me some junk
value for key..


 
code is incomplete so it is hard to say, but...
Are you checking file functions' return values ?
Do you close the file, and the open it again, if not, do you set back file pointer to correct place before reading?
I think it is some I/O error.

Regards
Pawel.
ASKER CERTIFIED SOLUTION
Avatar of Kimpan
Kimpan
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a million,dude.
You are welcome. Don't ask me if I have done this kind of errors myself before cause I have not! :)