Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(){
- FILE *fp;
- FILE *fh;
- FILE *fm;
- char nombre[60],sexo[2],input[60];
- int edad;
- fp=fopen("Estudiantes.txt", "r");
- fh=fopen("Hombres.txt", "w");
- fm=fopen("Mujeres.txt", "w");
- while(!feof(fp)){
- fscanf (fp, "%s%d%s", nombre, &edad, sexo);
- if(strcmp(sexo,"F")==0){
- fprintf(fm, "%s %d %s\n", nombre,edad,sexo);
- }
- if(strcmp(sexo,"M")==0){
- fprintf(fh, "%s %d %s\n", nombre,edad,sexo);
- }
- }
- fclose(fp);
- fclose(fh);
- fclose(fm);
- printf ("Ingrese el nombre de la persona que deseea buscar: ");
- scanf ("%s", input);
- fp=fopen("Estudiantes.txt", "r");
- while (!feof(fp)){
- fscanf (fp, "%s%d%s", nombre, &edad, sexo);
- if(strcmp(nombre,input)==0){
- printf ("Los datos de la persona buscada son:\nNombre: %s\nEdad: %d\nSexo:%s\n", nombre, edad,sexo);
- break;
- }
- else continue;
- }
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement