复制文件的C程序
2021-07-07 10:07:13
深夜i
--
--
复
制
文
件
的
C
程
序
复制文件的C程序:该程序复制文件,首先指定要复制的文件,然后输入目标文件的名称和扩展名。 我们将以“读取”模式打开要复制的文件,以“写入”模式打开目标文件。
C程序
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, source_file[20], target_file[20];
FILE *source, *target;
printf("Enter name of file to copy\n");
gets(source_file);
source = fopen(source_file, "r");
if (source == NULL)
{
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
printf("Enter name of target file\n");
gets(target_file);
target = fopen(target_file, "w");
if (target == NULL)
{
fclose(source);
printf("Press any key to exit...\n");
exit(EXIT_FAILURE);
}
while ((ch = fgetc(source)) != EOF)
fputc(ch, target);
printf("File copied successfully.\n");
fclose(source);
fclose(target);
return 0;
}
下载文件复制程序。
程序输出:
上一篇:
idea打包java可执行jar包
下一篇:
C程序合并两个文件
评论区