用C语言、系统IO实现文件复制(带进度条)

这篇博客展示了如何使用C语言实现文件复制,并在复制过程中添加进度条。通过读取源文件,然后以只写和创建的方式打开目标文件,进行内容写入,并实时更新进度条。代码中涉及了文件操作、内存管理和输入输出等C语言基础知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>

#define SIZE 50    //堆或者数组buffer的大小
#define W_BUF_SIZE 100    //文件复制过程中,设置写入缓冲区字节大小

int main(int argc, const char* argv[])
{
    /* //0.选择源文件、目标文件 */
    //输入src_file绝对路径名
    printf("pls input src_file_path: ");
    char *src_file=malloc(SIZE);
    bzero(src_file,SIZE);
    scanf("%s",src_file);while(getchar()!='\n');
    printf("src_file : %s\n",src_file);
    
    //输入des_file绝对路径名
    printf("pls input des_file_path: ");
    char *des_file=malloc(SIZE);
    bzero(des_file,SIZE);
    scanf("%s",des_file);while(getchar()!='\n');
    printf("des_file : %s\n",des_file);
    
    

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值