Advertisement
chalommm

CERTAMEN 3 (ARCHIVOS)

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