<分区>
FILE*
类型的给定参数 fd
,例如:
FILE* fd = fopen("a.txt","w")
。
如何删除a.txt
中的所有文本?
注意:我不知道文件的名称是什么(我正在编写一个函数,该函数获取有人已经在 main 中打开的 FILE*
类型的参数)。
例如:
FILE* fd = fopen("a.txt","w");
assert(fd != NULL); // it's not important for this question.
fprintf(fd,"hello1\n");
fprintf(fd,"hello2\n");
//.... and now I want to remove all the text from a.txt. How can I do it?
// The cleaning will be in other function that get just fd (without the
// name of the file)
fclose(fd);