Created
November 29, 2015 04:20
-
-
Save LaloHao/cd3da4ea83c3df806052 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| struct Estudiante{ | |
| char matricula[10]; | |
| char nombre[30]; | |
| }; | |
| int buscaAlumnoPorCodigo(struct Estudiante alumnos[], int cantidad, char matricula[]); | |
| int buscaAlumnoPorCodigo(struct Estudiante alumnos[], int cantidad, char matricula[]){ | |
| static int i, encontrado; | |
| encontrado = 0; | |
| for(i=0;i<cantidad;i++){ | |
| if(strcmp(alumnos[i].matricula, matricula)==0){ | |
| printf("Datos del alumno\nNombre: %s\n", alumnos[i].nombre); | |
| printf("Matricula: %s\n\n", alumnos[i].matricula); | |
| encontrado = 1; | |
| return i; | |
| } | |
| } | |
| if(!encontrado){ | |
| printf("No existe el alumno con matricula %s\n", matricula); | |
| } | |
| return -1; | |
| } | |
| void main(){ | |
| struct Estudiante alumnos[3]; | |
| strcpy(alumnos[0].matricula, "123456789"); | |
| strcpy(alumnos[0].nombre, "Este vato"); | |
| strcpy(alumnos[1].matricula, "098765432"); | |
| strcpy(alumnos[1].nombre, "Este otro vato"); | |
| strcpy(alumnos[2].matricula, "987654321"); | |
| strcpy(alumnos[2].nombre, "El otro vato"); | |
| buscaAlumnoPorCodigo(alumnos, 3, "123456789"); | |
| buscaAlumnoPorCodigo(alumnos, 3, "666999666"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment