Results 1 to 4 of 4

Thread: odd behaviour of fread

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    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.

  2. #2
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    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

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.

  4. #4

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    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
  •  



Click Here to Expand Forum to Full Width