秦晓彬 发表于 2014-4-6 21:58:44

文件操作,图片和txt做到一起了,怎么把它分开呢

#include <stdio.h>
#include <string.h>
#include <stdlib.h>// because use exit();

int main ()
{
        FILE *fp;
        FILE *rp;
        FILE *cp;
        char filename1;
        char filename2;
        char filename3;
//起始输入部分
lable1:;
        printf("please input the first filename:\n");
        gets(filename1);
        fp=fopen(filename1,"rb");
        if (NULL==fp)
        {
                printf("the first file open fail!!\n");
                //exit(0);
                goto lable1 ;
        }
lable2:;
        printf("please input the second filename:\n");
        gets(filename2);
        rp=fopen(filename2,"rb");
        if (NULL==rp)
        {
                printf("the second file open fail!!\n");
                //exit(0);
                goto lable2 ;
        }
lable3:;
        printf("please input the filename you want keep:\n");
        gets(filename3);
        cp=fopen(filename3,"ab+");
        if (NULL==cp)
        {
                printf("the file crate fail!!\n");
                //exit(0);
                goto lable3 ;
        }
        printf("writing……");
//文件写入部分
        int ch1;
        ch1=fscanf(fp,"%d",&ch1);
        while (feof(fp))
        {
                fprintf(cp,"%d",ch1);
                ch1=fscanf(fp,"%d",&ch1);
        }
        printf("the first file write success.\n");
        int ch2;
        ch2=fscanf(rp,"%d",&ch2);
        while (feof(rp))
        {
                fprintf(cp,"%d",ch2);
                ch2=fscanf(rp,"%d",&ch2);
        }
        printf("the second file write success.\n");
        fclose(fp);
        fclose(rp);
        fclose(cp);
        return 0;
}

通过上面的代码,我把a.jpg和a.txt做成了q.txt
但是当我把q的后缀改成.rar 时,用好压倒不开呀

页: [1]
查看完整版本: 文件操作,图片和txt做到一起了,怎么把它分开呢