Advertisement
Kl43z

Dakar/Certamen ARCHIVOS

Nov 27th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(){
  4.     FILE *ficha;
  5.     FILE *fcoches;
  6.     FILE *fmotos;
  7.     FILE *fcamiones;
  8.     FILE *fcuadrimotos;
  9.     int year;
  10.     char nombre[2],apellido[20], marca[20], tipo[20];
  11.     ficha=fopen("Dakar.txt", "r");
  12.     fcoches=fopen("coches.txt", "w");
  13.     fmotos=fopen("motos.txt", "w");
  14.     fcamiones=fopen("camiones.txt", "w");
  15.     fcuadrimotos=fopen("cuadrimotos.txt", "w");
  16.     while (!feof(ficha)){
  17.         fscanf (ficha, "%d%s%s%s%s", &year,nombre,apellido,marca,tipo);
  18.             if (strcmp(tipo,"Coches")==0)  
  19.                 fprintf (fcoches,"%d %s %s %s %s\n",year,nombre,apellido,marca,tipo );
  20.             else if (strcmp(tipo,"Motos")==0)  
  21.                 fprintf (fmotos,"%d %s %s %s %s\n",year,nombre,apellido,marca,tipo );
  22.             else if (strcmp(tipo,"Camiones")==0)       
  23.                 fprintf (fcamiones,"%d %s %s %s %s\n",year,nombre,apellido,marca,tipo );
  24.             else if (strcmp(tipo,"Cuadrimotos")==0)
  25.                 fprintf (fcuadrimotos,"%d %s %s %s %s\n",year,nombre,apellido,marca,tipo );
  26.     }
  27.     fclose(ficha);
  28.     fclose(fmotos);
  29.     fclose(fcoches);
  30.     fclose(fcamiones);
  31.     fclose(fcuadrimotos);
  32.     printf ("Listo\n");
  33.    
  34.    
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement