回复 14楼 Lin_credible
#include<stdio.h>
int copy_file(char *old_filename, char
*new_filename)
{
FILE
*ptr_old, *ptr_new;
errno_t err = 0, err1 = 0;
int
a;
err = fopen_s(&ptr_old, old_filename, "rb");
err1 = fopen_s(&ptr_new, new_filename, "wb");
if(err != 0)
return
-1;
if(err1 != 0)
{
fclose(ptr_old);
return
-1;
}
while(1)
{
a
=
fgetc(ptr_old);
if(!feof(ptr_old))
fputc(a, ptr_new);
else
break;
}
fclose(ptr_new);
fclose(ptr_old);
return
0;
}
int
main(void)
{
char
filename_src[101], filename_dest[101];
printf("\nSource file: ");
gets_s(filename_src, 100);
printf("\nDestination filename: ");
gets_s(filename_dest, 100);
if(copy_file(filename_src, filename_dest) == 0)
printf("Copy Successful\n");
else
fprintf(stderr, "Error during copy!");
}