Thread: fopen mode

  1. #1
    Registered User
    Join Date
    Sep 2008

    fopen mode

    I reviewed a piece of C code with intension of open a file to read and append.
    The code uses mode "ar", but I am not sure this is correct, because there is no such combination.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Use "r+" instead, then when you are done reading, seek to the end of the file and begin appending.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    It really should use "a+", although I expect that reading from a "a" file will work in many systems.

    Edit: Or as Laserlight says.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What mode should i use at fopen()? r, r+, w+b???
    By tirengarfio in forum C Programming
    Replies: 2
    Last Post: 08-13-2008, 06:42 AM
  2. console mode and service mode
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 01:42 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  4. Shortening main
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 03:56 PM
  5. Implementing "ls -al"
    By pdstatha in forum C Programming
    Replies: 7
    Last Post: 03-06-2002, 04:36 PM
Website Security Test