Hi,
is there any way to erase the contend of a file without erasing the file????
Hi,
is there any way to erase the contend of a file without erasing the file????
open it in "w" mode. that will erase the file content.
niara
thanks
^^
High I myself just recently created a simple program to test a few functions and opening the file in "w" (write mode) didn't erase any data in it, instead it just wrote after all the data. However I found that in such a case the following fprintf statement works just as well:
/* Must include this .h header file */
#include <config.h>
/* Replace file with a char pointer pointing to the file location */
/* The quotation marks basicly just tells fprintf to not print anything at all and instead use the systems clear comand to clear all data within a file. */
fprintf(file, "", system("clear"));
No, don't make a call to the system.
Instead of using "w" use "w+"
Sent from my iPadŽ
tuxinator, that line does the same to the file as:All system("clear") does is clear your terminal, and return 0 for the third parameter of fprintf, which is ignored, because your format specifier (the second parameter) is empty.Code:fprintf(file, "");
That shouldn't make any difference.Originally Posted by SlyMaelstrom
Last edited by cwr; 12-01-2005 at 12:18 AM.
Hm... I'll have to do some more testing with my code then because before when I first had the fopen mode set to "w" and didn't have any function to clear the file it just outputted the information after the previous information.
P.S. I am currently working on creating a copy of my code and compiling both to see if they both give the same output. If they don't then I will post both codes online and a precompiled version in case it is a problem with my compiler.
Hmmm I thought "w" appends.
Sent from my iPadŽ
The FAQ page has a section that explains what each mode represents.Originally Posted by SlyMaelstrom