What mode should i use at fopen()? r, r+, w+b???

This is a discussion on What mode should i use at fopen()? r, r+, w+b??? within the C Programming forums, part of the General Programming Boards category; Hi, im trying to create a code which opens a text file, writes some content from that text file (fwrite) ...

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

    What mode should i use at fopen()? r, r+, w+b???

    Hi,

    im trying to create a code which opens a text file, writes some content from that text file (fwrite) and then reads a part of that content (fread). Finally i close the file (fclose)

    What mode should i use at fopen() to do these operations ? r, r+, w+b???

    Bye

    Javi

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    99
    Think Google might help?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If it's a TEXT file, you should most likely not use "b" in the mode.

    "w+" and "r+" both mean that you want to read and write the file, but "w" means create an empty file, "r" means that you open an existing file.

    Generally you don't use fread() and fwrite() on text files, althouth there is nothing technically wrong with it.

    --
    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. fopen mode
    By CGong in forum C Programming
    Replies: 2
    Last Post: 09-04-2008, 08:17 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