Thread: truncating a file to 0 length

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    27

    truncating a file to 0 length

    Is there a way to truncate a file to 0 length in C?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Yes, but why would you want to do that?

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    All you have to do is fopen() the file in "w" mode. If the file exists, it will be truncated to 0 bytes. If it doesn't exist, it will create it.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM