| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1458 人关注过本帖
标题:[求助] 急急!!高手进来解决个问题
只看楼主 加入收藏
harker007
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-9-14
收藏
 问题点数:0 回复次数:0 
[求助] 急急!!高手进来解决个问题
下面的程序我打开一文件往里面随机写入数据,然后删除;但是我用恢复软件恢复出来以后是我以前的原始数据,但是我要是去掉删除的代码自己手动删除的话恢复出来的就是随机数据啦 不知道为什么 高手解答
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#define REWRITECOUNT 10//重写文件次数
int main(int argc,char *argv[])
{
DWORD dwsizelow,dwsizehigh;
DWORD dwRet;
char * Buffer;
UINT i,j;
HANDLE hFile=CreateFile( "E:\\3.txt ",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
printf( "Can 't open the file.\n ");
ExitProcess(0);
}
dwsizelow=GetFileSize(hFile,&dwsizehigh);
if(dwsizelow!=0xFFFFFFFF)
{
printf( "the file size is %u\n ",dwsizelow);
}
else
{
printf( "obtain the file length failed.\n ");
ExitProcess(0);
}
srand((int)time(0));
Buffer=(char *)malloc(dwsizelow*sizeof(char));
for(j=0;j <REWRITECOUNT;j++)
{
for(i=0;i <dwsizelow;i++)//Buffer数组内容随机产生
{
Buffer[i]=rand()%255;
printf( "%c ",Buffer[i]);
}
printf( "\n ");
WriteFile(hFile,Buffer,dwsizelow,&dwRet,NULL);//将Buffer数组写到文件中
SetFilePointer(hFile,0,NULL,FILE_BEGIN);//将文件指针调回文件开始处
}
free(Buffer);
CloseHandle(hFile);

if(DeleteFile( "E:\\3.txt "))//删除文件
{
printf( "delete file success.\n ");
}
else
{
printf( "delete file failed.%i\n ",GetLastError());
ExitProcess(0);
}
// ExitProcess(1);
}
搜索更多相关主题的帖子: windows include int DWORD 
2008-05-25 09:57
快速回复:[求助] 急急!!高手进来解决个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014434 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved