Advertisement
Guest User

AnB

a guest
Sep 21st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. int crearC(const char* nombreA,const char* nombreB,const char* nombreC)
  2. {
  3.     int auxA,auxB;
  4.     FILE*Archivo_A;
  5.     FILE*Archivo_B;
  6.     FILE*Archivo_C;
  7.     Archivo_A=fopen(nombreA,"rb");
  8.     if(!Archivo_A)
  9.     {
  10.         printf("ERROR AL LEER A\n");
  11.         return -1;
  12.     }
  13.     Archivo_B=fopen(nombreB,"rb");
  14.     if(!Archivo_B)
  15.     {
  16.         if(Archivo_A)
  17.         {
  18.             fclose(Archivo_B);
  19.         }
  20.         printf("ERROR AL LEER B\n");
  21.         return -1;
  22.     }
  23.     Archivo_C=fopen(nombreC,"wb");
  24.     if(!Archivo_C)
  25.     {
  26.         if(Archivo_A)
  27.             fclose(Archivo_A);
  28.         if(Archivo_B)
  29.             fclose(Archivo_B);
  30.         printf("ERROR AL ESCRIBIR C\n");
  31.         return -1;
  32.     }
  33.     fread(&auxA,sizeof(int),1,Archivo_A);
  34.     fread(&auxB,sizeof(int),1,Archivo_B);
  35.     while(!feof(Archivo_A)&&!feof(Archivo_B))
  36.     {
  37.         while(auxA<auxB)
  38.         {
  39.             fread(&auxA,sizeof(int),1,Archivo_A);
  40.         }
  41.         if(auxA==auxB)
  42.         {
  43.             fwrite(&auxA,sizeof(int),1,Archivo_C);
  44.             fread(&auxA,sizeof(int),1,Archivo_A);
  45.             fread(&auxB,sizeof(int),1,Archivo_B);
  46.         }
  47.         while(auxA>auxB)
  48.         {
  49.             fread(&auxB,sizeof(int),1,Archivo_B);
  50.         }
  51.  
  52.  
  53.     }
  54.     fclose(Archivo_A);
  55.     fclose(Archivo_B);
  56.     fclose(Archivo_C);
  57.     return 0;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement