0
How can I delete the contents of a file in c, which function should I use?
#include <stdio.h>
#include <stdlib.h>
void main(){
char hello[13] = "Hello World!";
char path[12] = "arquivo.txt";
FILE* arquivo;
arquivo = fopen(path, "a+");
fprintf(arquivo, hello);
printf("%s foi adicionado ao arquivo %s", hello, path);
/*
arquivo = fopen(path, "w");
fclose(arquivo);
*/
}
All content?
– Maniero
yes, delete all content from a text file
– Vanderson
Open the file in mode
w
does not delete the previous content?– Woss
It’s literally just doing
fopen
withw
as @Andersoncarloswoss said– Isac
I tried to open with w, but it didn’t erase
– Vanderson
And why not delete the file purely and simply?
– Maniero