fwrite

This is a discussion on fwrite within the Windows Programming forums, part of the Platform Specific Boards category; Why isn't this working? fwrite( notes->notes, sizeof( NOTE ), notes->nChildren, dbFile ); notes->notes is an array of NOTE, the array ...

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    fwrite

    Why isn't this working?

    fwrite( notes->notes, sizeof( NOTE ), notes->nChildren, dbFile );

    notes->notes is an array of NOTE, the array size being notes->nChildren ...

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Don't know. Things to check include return value from fwrite, whether notes->notes is pointing to what you think it should be pointing to, notes->nChildren is a valid value (and that there are that number of NOTES pointed to by notes->notes) and that dbFile is a valid *FILE. Try replacing some of the values with literals and see if that works as expected.

    If you need more help you're going to have to post more code, preferrably a small example that reproduces the problem.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Why don't you check the return result from fwrite(), and also the return result from ferror() following a call to fwrite()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Alrighty, I've found my problem I think ...

    nChildren = 0, but it is still written as expected...But notes isn't written because it is 0 ..

    Should be able to fix it, thanks ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using fwrite
    By kenkoh in forum C Programming
    Replies: 10
    Last Post: 02-16-2008, 09:34 AM
  2. WriteFile and fwrite
    By George2 in forum C Programming
    Replies: 4
    Last Post: 08-10-2007, 04:33 AM
  3. fwrite error: bad address
    By icebabe in forum C Programming
    Replies: 6
    Last Post: 05-06-2006, 06:35 AM
  4. Determining fwrite errors
    By cboard_member in forum C Programming
    Replies: 2
    Last Post: 04-26-2006, 05:30 AM
  5. fwrite file size
    By lambs4 in forum C Programming
    Replies: 4
    Last Post: 04-04-2003, 04:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21