回覆列表
  • 1 # 匠工加工網

    #include<stdio.h>

    #include<stdlib.h>

    #include<string.h>

    void main()

    {

    FILE *fpa,*fpb,*fpc;

    char k[300]={0},kk[300]={0}; //k是b裡的字串,kk是a裡的字串

    fpa=fopen("a.txt","r");

    fpb=fopen("b.txt","r");

    fpc=fopen("c.txt","w"); //先把內容存在檔案c裡,再轉到a裡面

    if(fpa==NULL||fpb==NULL)

    {

    printf("開啟檔案失敗\n");

    printf("請確認你是否已新建好\"a.txt\"和\"b.txt\"\n");

    return;

    }

    fscanf(fpb,"%s",k);

    fscanf(fpa,"%s",kk);

    {

    if(strcmp(kk,k)!=0) /* 無相同內容 */

    {

    fprintf(fpc,"%s\n",kk);

    }

    memset(kk,0,sizeof(kk));

    fscanf(fpa,"%s",kk);

    }

    fclose(fpa);

    fclose(fpb);

    fclose(fpc);

    fpc=fopen("c.txt","r");

    fpa=fopen("a.txt","w");

    memset(kk,0,sizeof(kk));

    fscanf(fpc,"%s",kk);

    while(kk[0]!="\0") //開始轉到a裡面

    {

    fprintf(fpa,"%s\n",kk);

    memset(kk,0,sizeof(kk));

    fscanf(fpc,"%s",kk);

    }

    fclose(fpc);

    system("del c.txt"); //把新建的c.txt刪掉

    printf("已完成\n");

    }

  • 中秋節和大豐收的關聯?
  • 輔警年齡大了還有哪些職業上的選擇?