open empty file

This is a discussion on open empty file within the C Programming forums, part of the General Programming Boards category; hey im programming in c under linux , and i want to open a new EMPTY file , im using ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    13

    open empty file

    hey
    im programming in c under linux , and i want to open a new EMPTY file , im using the "open" system call . this is my code:
    Code:
     fd=open(filename, O_WRONLY | O_CREAT);
    but this open me the old file (if there is such one) ... and i want to open a new empty one..

    how can i do this ?
    thanks !

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add O_TRUNC to "remove" the old file-content [truncate the file to 0 size].

    --
    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.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    13
    thanks !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

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