-4
I need to show a student’s chart using the license plate, as I do?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main() {
struct ficha {
char matricula[9], inf[9];
char nome[50];
char curso[20];
char periodo[10];
};
struct ficha alunos[2];
int i;
for (i = 0; i < 2; i++) {
printf("\nInforme a matricula do aluno: ");
scanf("%s", & alunos[i].matricula);
printf("\nInforme o nome do aluno: ");
scanf("%s", & alunos[i].nome);
printf("\nInforme o curso do aluno: ");
scanf("%s", & alunos[i].curso);
printf("\nInforme o periodo do aluno: ");
scanf("%s", & alunos[i].periodo);
}
printf("\n\nDigite uma das matriculas para informacoes de um aluno:");
scanf("%s", & alunos[i].inf);
if (strcmp(alunos[i].matricula, alunos[i].inf) == 0) {
printf("\n\n---------------------------Informacoes---------------------------\n\n");
printf("\nMatricula: %s \n", alunos[i].matricula);
printf("\nNome: %s \n", alunos[i].nome);
printf("\nCurso: %s \n", alunos[i].curso);
printf("\nPeriodo: %s \n", alunos[i].periodo);
} else
printf("Aluno nao encontrado");
system("pause");
}
scanf("%s", & alunos[i].inf);note in your code that this line is outside thefor, ie, will use the last value you have in the variable "i". this property "inf" would not need to be instructif it will read only once, it could be a common variable. And it should then do aforto find this value and see if it was typed– Ricardo Pontual