#include "stdio.h"
#include "stdlib.h"
#include <malloc.h>
#include "string.h"
#include "windows.h"
#define path "c:\\calc.exe"
#define Newpath "c:\\calcNew.exe"
int GetFsize(FILE* pf)
{
fseek(pf,0,SEEK_END);
int size=ftell(pf);
return size;
}
void main()
{
FILE* PFile;
FILE* PFileNew;
PFile=fopen(path,"rb");
PFileNew=fopen(Newpath,"wb");
if (PFile==NULL||PFileNew==NULL)
{
printf("文件打开和创建失败!\n");
return;
}
int size=GetFsize(PFile);
printf("%d字节\n",size);
char* pmalloc=(char*)malloc(sizeof(char)*size);
printf("%p\n",pmalloc);
memset(pmalloc,0,sizeof(char)*size+1);
fseek(PFile,0,SEEK_SET);
for (int i=0;i<size;i++)
{
fread(pmalloc,sizeof(char),size,PFile);
}
fseek(PFileNew,0,SEEK_SET);
for (int k=0; k<size; k++)
{
fwrite(pmalloc,sizeof(char),size,PFileNew);
}
system("pause");
}