Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/11/2010, 11:13
jorgevivojmnz
 
Fecha de Ingreso: noviembre-2010
Mensajes: 6
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Ejercicio de Funciones

Sobre todo estoy bloqueado con el apartado B, ya que se copiar un archivo en otro, pero no se hacer que lo que me pide en el apartado b.
Código C:
Ver original
  1. /* Copia de un fichero a otro con otro nombre */
  2.  
  3.       #include <stdio .h>
  4.  
  5.       main(argc,argv)
  6.  
  7.       int argc;
  8.  
  9.       char *argv[];
  10.  
  11.       {
  12.  
  13.       FILE *origen, *destino;char car, aux1, aux2; int i=0, igu=1;
  14.  
  15.       if (argc != 3)
  16.  
  17.       {
  18.  
  19.       printf ("Error. La instruccion es:\n copia fichero_origen fichero_destino\n");
  20.  
  21.       return;
  22.  
  23.       }
  24.  
  25.       do
  26.  
  27.       {
  28.  
  29.       aux1=*(argv[1]+i);
  30.  
  31.       aux2=*(argv[2]+i);
  32.  
  33.       if (aux1 != aux2)
  34.  
  35.       {
  36.  
  37.       igu=0;
  38.  
  39.       break;
  40.  
  41.       }
  42.  
  43.       i++;
  44.  
  45.       } while (aux1 != '\0' || aux2 != '\0');
  46.  
  47.       if (igu == 1)
  48.  
  49.       {
  50.  
  51.       printf ("El fichero destino es el mismo que el fichero origen\n");
  52.  
  53.       return;
  54.  
  55.       }
  56.  
  57.       origen=fopen(argv[1],"r");
  58.  
  59.       destino=fopen(argv[2],"w");
  60.  
  61.       if (origen==NULL || destino ==NULL)
  62.  
  63.       {
  64.  
  65.       printf ("El fichero de origen no existe o no hay espacio en el disco\n");
  66.  
  67.       return;
  68.  
  69.       }
  70.  
  71.       while ( (car=getc(origen)) != EOF ) putc(car,destino);
  72.  
  73.       fclose(origen);
  74.  
  75.       fclose(destino);
  76.  
  77.       }
  78.  
  79.       char car, aux1, aux2;
  80.  
  81.       int i=0, igu=1;
  82.  
  83.       if (argc != 3)
  84.  
  85.       {
  86.  
  87.       printf ("Error. La instruccion es:\n copia fichero_origen fichero_destino\n");
  88.  
  89.       return;
  90.  
  91.       }
  92.  
  93.       do
  94.  
  95.       {
  96.  
  97.       aux1=*(argv[1]+i);
  98.  
  99.       aux2=*(argv[2]+i);
  100.  
  101.       if (aux1 != aux2)
  102.  
  103.       {
  104.  
  105.       igu=0;
  106.  
  107.       break;
  108.  
  109.       }
  110.  
  111.       i++;
  112.  
  113.       } while (aux1 != '\0' || aux2 != '\0');
  114.  
  115.       if (igu == 1)
  116.  
  117.       {
  118.  
  119.       printf ("El fichero destino es el mismo que el fichero origen\n");
  120.  
  121.       return;
  122.  
  123.       }
  124.  
  125.       origen=fopen(argv[1],"r");
  126.  
  127.       destino=fopen(argv[2],"w");
  128.  
  129.       if (origen==NULL || destino ==NULL)
  130.  
  131.       {
  132.  
  133.       printf ("El fichero de origen no existe o no hay espacio en el disco\n");
  134.  
  135.       return;
  136.  
  137.       }
  138.  
  139.       while ( (car=getc(origen)) != EOF ) putc(car,destino);
  140.  
  141.       fclose(origen);
  142.  
  143.       fclose(destino);
  144.  
  145.       }