| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1723 人关注过本帖
标题:怎么复制文件内容的同时输出进度百分比? 新手求助
只看楼主 加入收藏
bb102
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2016-10-22
结帖率:88.89%
收藏
已结贴  问题点数:10 回复次数:18 
怎么复制文件内容的同时输出进度百分比? 新手求助
#include<stdio.h>
#include<stdlib.h>
void main()
{
    FILE *in,*out;
    char ch,infile[10],outfile[10];
    printf("enter the name of the fileread:");
    scanf("%s",infile);
    printf("enter the name of the filewrite:");
    scanf("%s",outfile);
    if((in=fopen(infile,"r"))==NULL)
    {
        printf("can not open the file!\n");
        exit(0);
    }
    if((out=fopen(outfile,"w"))==NULL)
    {
        printf("can not open the file!\n");
        exit(0);
    }
    while(!feof(in))
    {
        ch=fgetc(in);
        fputc(ch,out);
        putchar(ch);
    }
    putchar(10);
    fclose(in);
    fclose(out);
}
搜索更多相关主题的帖子: include 百分比 file 
2016-12-29 21:02
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
控制台程序下 很难实现

DO IT YOURSELF !
2016-12-29 21:04
bb102
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2016-10-22
收藏
得分:0 
回复 2楼 wp231957
原理是将已经复制的数目和字符的总数目相比,但是不知道怎么实现
2016-12-29 21:08
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
可以试试以下代码 :
程序代码:
#include <stdio.h>
#include <windows.h>
#include <string.h>

int main()
{
    int i,len,k;
    printf("\n\n");
    char* test="Now it will copping completed: ";
    len=(int)strlen(test);
    for (i=0;i<=100;i++)
    {
        printf("%s %8.2lf",test,1.0*i/100*100);
        Sleep(80);
        for(k=0;k<len+9;k++) printf("\b");
    }
    printf("\n");
    return 0;
}


 

[此贴子已经被作者于2016-12-29 21:30编辑过]


DO IT YOURSELF !
2016-12-29 21:26
bb102
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2016-10-22
收藏
得分:0 
回复 4楼 wp231957
怎么把这两个代码合在一起呢?这部分不太会啊
2016-12-29 21:35
bb102
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2016-10-22
收藏
得分:0 
回复 4楼 wp231957
怎么把这两个代码合在一起呢?这部分不太会啊
2016-12-29 21:35
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
把我的代码融入你的代码倒是可以
你的问题主要是如何获取文件的长度 这是关键

DO IT YOURSELF !
2016-12-29 21:47
bb102
Rank: 1
等 级:新手上路
帖 子:83
专家分:3
注 册:2016-10-22
收藏
得分:0 
回复 7楼 wp231957
2016-12-29 21:56
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
今天是不行了。电脑关机。 准备呼呼呼呼了

DO IT YOURSELF !
2016-12-29 22:03
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
收藏
得分:0 
程序代码:
#include<stdio.h>
#include<windows.h>

 #include<stdlib.h>
  main()

 {
      int len = 0 ,t = 0 ,l = 0;
     FILE *in,*out;
     char ch,infile[10],outfile[10];
     printf("enter the name of the fileread:");
     scanf("%s",infile);
     printf("enter the name of the filewrite:");
     scanf("%s",outfile);
     if((in=fopen(infile,"r"))==NULL)
     {
         printf("can not open the file!\n");
         exit(0);
     }
     if((out=fopen(outfile,"w"))==NULL)
     {
         printf("can not open the file!\n");
         exit(0);
     }
     
     ch = fgetc(in);
     while(!feof(in))
     {
            len++;
            ch = fgetc(in);
     }
     fseek(in, 0L,0);
     
     while(!feof(in))
     {
         t++;
         ch=fgetc(in);
         fputc(ch,out);
         putchar(ch);
         printf("\t\t");
         printf("%2.0lf", 1.0*100*(t-1)/len);
         Sleep(300);
         for(l = 0; l <len +t+2; l++)
         {
             printf("\b");
         }
         
     }
     putchar(10);
     fclose(in);
     fclose(out);

 }

早知做人那么辛苦!  当初不应该下凡
2016-12-29 22:07
快速回复:怎么复制文件内容的同时输出进度百分比? 新手求助
数据加载中...
 
   



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

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