文件的合并于读取

一剑行天下 posted @ 2008年11月01日 23:29 in 学习 , 1209 阅读

 

#include<stdio.h>
main()
{
        FILE *fp;
        char c[10000],ch;char t;
        long int i,j,n;
        if((fp=fopen("a1","r"))==NULL)
        {
                printf("can not open the file\n");
                return(0);
        }
        printf("file a1\n");
        for(i=0;(ch=fgetc(fp))!=EOF;i++)
        {
                c[i]=ch;
                putchar(ch);
        }
        fclose(fp);
        if((fp=fopen("b1","r"))==NULL)
        {
                printf("can not open the file\n");
                return(0);
       
        }
        printf("file b1\n");
        for(j=i;(ch=fgetc(fp))!=EOF;j++)
        {
                c[j]=ch;
                putchar(ch);
         }
        fclose(fp);
        n=j;
        for(i=0;i<n;i++)
                for(j=i+1;j<n;j++)
                {
                        if(c[i]<c[j])
                        {
                                t=c[i];
                                c[i]=c[j];
                                c[j]=t;
                       
                        }
                }
        fp=fopen("c1","w");
       
        printf("the file c1\n");
        for(i=0;i<n;i++)
        {
                fputc(c[i],fp);
                putchar(c[i]);

        }

       
    fclose(fp);
}
 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter