Determining fwrite errors

This is a discussion on Determining fwrite errors within the C Programming forums, part of the General Programming Boards category; I read the MSDN entry on fwrite() and it says that fwrite may return a number less than count if ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Determining fwrite errors

    I read the MSDN entry on fwrite() and it says that fwrite may return a number less than count if there was an error. Since I don't like the sound of may I just wanted to run this by someone:

    Code:
        if (target & LOG_ENGINE)
            if (fwrite(buffer, sizeof *buffer, strlen(buffer), engineLog) < strlen(buffer)) return gfalse;
    Is that a / the ("best") way to check if fwrite has failed?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    You could check what ferror() returns.
    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.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Oh aye. Cheers.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

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