|
-
Mar 1st, 2005, 05:54 AM
#1
Thread Starter
transcendental analytic
odd behaviour of fread
Two things, fread reads 1 byte when its suppose to read 4, but get no errors nor has it reached end of file, and the other thing is that it jumps to 245, can anyone explain this?
getpos(f,&pos);
Debug << pos <<endl;// says 0
size_t s;Debug<<fread(&s,sizeof(size_t),1,f)<<endl;_node.resize(s);//says 1
Debug<<ferror(f)<<endl;//says 0
Debug<<feof(f)<<endl;//says 0
fgetpos(f,&pos);
Debug << pos <<endl;//says 245
fread(&s,sizeof(size_t),1,f);_edge.resize(s);
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Mar 2nd, 2005, 02:44 PM
#2
PowerPoster
Re: odd behaviour of fread
Your code is a mess.
But, if it says 245 then it is jumpin that far. Are you sure the struct in the first read isn't 245 bytes large?? 245 is a weird one to end up as well especially if you are using MSVC since padding keeps it all to divisible by DWORD.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Mar 3rd, 2005, 01:48 PM
#3
Re: odd behaviour of fread
The fread return value is fine:
fread returns the number of full items actually read,
Does fgetpos return 0?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 3rd, 2005, 03:35 PM
#4
Thread Starter
transcendental analytic
Re: odd behaviour of fread
i ditched fread some time ago, and switched to ifstream, works better now, thanks for answering anyway
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|