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.
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.
Could you post the code?
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,f p);
Now an fread(&p,sizeof(page),1,fp ) returns me some junk
value for key..
{
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,f
Now an fread(&p,sizeof(page),1,fp
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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! :)