Advertisement
Kl43z

Estudiantes ARCHIVO

Dec 2nd, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(){
  4.     FILE *fp;
  5.     FILE *fh;
  6.     FILE *fm;
  7.     char nombre[60],sexo[2],input[60];
  8.     int edad;
  9.     fp=fopen("Estudiantes.txt", "r");
  10.     fh=fopen("Hombres.txt", "w");
  11.     fm=fopen("Mujeres.txt", "w");
  12.  
  13.     while(!feof(fp)){
  14.         fscanf (fp, "%s%d%s", nombre, &edad, sexo);
  15.         if(strcmp(sexo,"F")==0){
  16.                 fprintf(fm, "%s %d %s\n", nombre,edad,sexo);
  17.             }
  18.         if(strcmp(sexo,"M")==0){
  19.                 fprintf(fh, "%s %d %s\n", nombre,edad,sexo);
  20.             }
  21.     }
  22.     fclose(fp);
  23.     fclose(fh);
  24.     fclose(fm);
  25.     printf ("Ingrese el nombre de la persona que deseea buscar: ");
  26.     scanf ("%s", input);
  27.     fp=fopen("Estudiantes.txt", "r");
  28.         while (!feof(fp)){
  29.             fscanf (fp, "%s%d%s", nombre, &edad, sexo);
  30.            
  31.             if(strcmp(nombre,input)==0){
  32.                 printf ("Los datos de la persona buscada son:\nNombre: %s\nEdad: %d\nSexo:%s\n", nombre, edad,sexo);
  33.                 break;
  34.             }
  35.             else continue;
  36.                
  37.         }
  38.     fclose(fp);
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement