免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 932 | 回复: 4
打印 上一主题 下一主题

新手问一个小问题,望高手赐教一下。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 19:36 |只看该作者 |倒序浏览
本帖最后由 jan1990 于 2011-12-23 19:39 编辑


#include <sys/types.h>
#include <stdio.h>
#define BUF_SIZE 1024
int main(void)
{
        char buf[BUF_SIZE]={'\0'};
        FILE *source, *backup;
        if((source=fopen("source.dat", "rb"))==NULL)
        {
            printf("Error in opening file.\n");
               exit(1);
        }
        if((backup=fopen("backup.dat", "wb"))==NULL)
        {
            printf("Error in creating file.\n");
               exit(1);
        }
        while(1)
        {   
        fread(buf, sizeof(buf), 1, source);
            if(!fwrite(buf, sizeof(buf), 1,backup))
            {
                    printf("Error in wrinting file.\n");
                    exit(1);
            }
        if(feof(source)) break;
        fseek(source,sizeof(buf),1);
        fseek(backup,sizeof(buf),1);
        }
        if(ferror(source))
    {
            printf("Error in reading file.\n");
            exit(1);
    }
        if(fclose(source))
        {
            printf("Error in close file.\n");
            exit(1);
        }
        if(fclose(backup))
    {
            printf("Error in close file.\n");
            exit(1);
        }
}


请问我这个程序哪里出错了?运行的时候我不能打开backup.dat文件,我不知道是哪里出错了。。求指教

论坛徽章:
0
2 [报告]
发表于 2011-12-23 19:40 |只看该作者
这是我第一次来这里求教,先谢谢了~~~

论坛徽章:
0
3 [报告]
发表于 2011-12-23 19:42 |只看该作者
忘记说了,我是在xinyang系统下运行的

论坛徽章:
0
4 [报告]
发表于 2011-12-23 22:44 |只看该作者
多研究下   总会明白过来的










美国种蚂                 莎狐净                        红酒木瓜靓汤

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
5 [报告]
发表于 2011-12-23 23:00 |只看该作者
你需要去程序设计相关版块提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP