#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
int size;
FILE *fp;
fp=fopen("prova" , "rb");
if(fp == NULL){
printf("%s",strerror(2));
return EXIT_FAILURE;
}
/* Controllo lunghezza file */
fseek(fp, 0, SEEK_END);
size=ftell(fp);
fseek(fp, 0, SEEK_SET);
/* --- */
for(i=1; i<=size; i++){
qualcosa
}
fclose(fp);
return EXIT_SUCCESS;
}
我想通过用 0x00 覆盖文件来“安全删除”文件...就像/dev/zero 所做的那样! 我该怎么做? 我已经打开了文件,我已经检查了他的长度......现在呢?
最佳答案
首先,您打开它只是为了阅读:
fp=fopen("prova" , "rb");
您需要:
fp=fopen("prova" , "w+");
之后,您只需向文件写入零,直到达到使用 fputc()
或 fwrite()
确定的长度
我认为这实际上可能无法解决您的实际问题,具体取决于操作系统。它最终可能会将文件写入磁盘上的不同区域(从而保持原始数据不变)
关于c - 将 0x00 覆盖到文件 C 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7539827/