fopen mode

This is a discussion on fopen mode within the C Programming forums, part of the General Programming Boards category; I reviewed a piece of C code with intension of open a file to read and append. The code uses ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    1

    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
    Location
    Singapore
    Posts
    22,159
    Use "r+" instead, then when you are done reading, seek to the end of the file and begin appending.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

    Edit: Or as Laserlight says.

    --
    Mats
    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, 07:42 AM
  2. console mode and service mode
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-01-2008, 02:42 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. Shortening main
    By pdstatha in forum C Programming
    Replies: 1
    Last Post: 04-03-2002, 04:56 PM
  5. Implementing "ls -al"
    By pdstatha in forum C Programming
    Replies: 7
    Last Post: 03-06-2002, 05:36 PM

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