When I do a print in my string array this is showing some symbols and not the words. The array is located in the void query function. I put all the code because it may be a mistake somewhere else but I'm not finding it.
Exercise asks for this.
• When associating a student with a subject, check if the required time blocks are available in the student grid, if yes, associate the subject, otherwise display a message stating the conflict. For example, if the student is already associated with a discipline that occurs on Tuesday the 13th, you will not be able to add another discipline that occurs on the same day and time. See Table 1, disciplines 0127 and 0132. • When entering students email, validate if the email is correct: The. Email must have: 3 characters or more; an at sign ("); other 3 characters or more; followed by an endpoint (.) signal; and a set of at least 2 characters;
• Allow students to be consulted by name or part of the name. When you find it, allow to see your data and your hourly grid. • Example, student Pedro should be found with "Ped" (from 3 characters);
• The subject information is stored in the list of subjects; information about students is stored in the student list. Make a link, as seen in class, between them, do not duplicate the data.
Below the code this is how it should be presented. the code was a bit messy because I do not know how to format it on the site yet.
#include < stdio.h > #include < string.h >
struct disciplinas {
int codigo;
char nome[20];
char professor[20];
int c_Horaria;
char h_Semanal[30];
};
struct registro {
int matricula;
char nome[20];
char sobrenome[20];
char email[40];
int l_Disciplinas[5];
};
struct grade {
char grade_C[4][5];
};
int cont;
void add_Aluno(struct registro al[3], struct disciplinas add_Dis[5], struct grade g_Materias[4][5]) {
int dis, x, y, guarda[5], cont = 0, num;
char resp;
printf("\n\n");
printf("--------------------------------------\n");
printf("---Voce selecionou adicionar aluno.---\n");
printf("--------------------------------------\n");
printf(" Lista de Disciplinas\n");
printf(" Codigo Nome\n\n");
for (x = 0; x < 5; x++) {
printf(" %d %s \n", add_Dis[x].codigo, add_Dis[x].nome);
}
printf("\n");
printf(" Horas Horario\n\n");
for (x = 0; x < 5; x++) {
printf(" %d %s\n", add_Dis[x].c_Horaria, add_Dis[x].h_Semanal);
}
printf("\n");
do {
x = 0;
printf("Digite seu nome:");
fflush(stdin); //Funcão de Cadastro do aluno
gets(al[cont].nome);
printf("Digite seu Sobrenome:");
gets(al[cont].sobrenome);
strcat(al[cont].nome, al[cont].sobrenome);
printf("Digite sua Matricula:");
scanf("%d", & al[cont].matricula);
printf("Digite seu e-mail:");
fflush(stdin);
gets(al[cont].email);
printf("Digite em quantas materias deseja se matricular:");
scanf("%d", & num);
printf("Digite o codigo das diciplinas que voce deseja se matricular\n");
cont++;
for (y = 0; y < num; y++) {
scanf("%d", & al[y].l_Disciplinas);
}
for (x = 0; x < num; x++) {
if (al[x].l_Disciplinas == 122)
//Adiciona as disciplinas para as posiçoes
//da matriz
{
strcpy(g_Materias[0][0].grade_C, "Algo");
strcpy(g_Materias[1][1].grade_C, "Algo");
} else if (al[x].l_Disciplinas == 127) {
strcpy(g_Materias[2][1].grade_C, "Estr");
strcpy(g_Materias[4][2].grade_C, "Estr");
} else if (al[x].l_Disciplinas == 132) {
strcpy(g_Materias[2][1].grade_C, "Sist");
strcpy(g_Materias[1][3].grade_C, "Sist");
} else if (al[x].l_Disciplinas == 143) {
strcpy(g_Materias[1][4].grade_C, "Padr");
} else if (al[x].l_Disciplinas == 143) {
strcpy(g_Materias[1][2].grade_C, "Banc");
strcpy(g_Materias[1][4].grade_C, "Banc");
}
}
printf("Deseja Cadastrar outro aluno? s/n:");
fflush(stdin);
scanf("%c", & resp);
} while (x = !'n');
}
void consulta(struct registro al_C[3], struct grade grade_M[4][5]) {
int x, escolhe, a, b;
char nome[20];
char salva[3];
int cont_L = 0;
int teste[3];
char resp;
int matricula_N;
printf("\n\n");
printf("--------------------------------------\n");
printf("---Voce selecionou Consultar aluno.---\n");
printf("--------------------------------------\n");
printf("1.Pesquisa por Nome\n");
printf("2.Pesquisa por Matricula\n");
scanf("%d", & escolhe);
do {
if (escolhe == 1) {
printf("Digite o nome do aluno:");
fflush(stdin);
gets(nome);
for (x = 0; x < 4; x++) {
if (al_C[x - 2].nome == ' ') {
//copia as 3 primeiras letras para dentro do vetor salva
strcpy(salva, al_C[x - 2].nome);
strcpy(teste, salva);
}
if (strcmp(al_C[x].nome, nome) == 0 || strcmp(teste, salva) == 0) {
//compara os nomes ou compara a 3 letras dos dois nome se for igual ele printa a grade
for (a = 0; a < 4; a++) {
for (b = 0; b < 5; b++) {
printf("%s", grade_M[a][b].grade_C);
}
}
}
}
} else if (escolhe == 2) {
printf("Digite a Matricula do aluno:");
fflush(stdin);
scanf("%d", & matricula_N);
for (x = 0; x < 4; x++) {
if (al_C[x].matricula == matricula_N);
//compara as duas matricular se são iguais se for ele printa a grade do aluno
{
for (a = 0; a < 4; a++) {
for (b = 0; b < 5; b++) {
printf("%s", grade_M[a][b].grade_C);
}
printf("\n");
}
}
}
}
printf("Deseja consultar outro aluno? S/N");
fflush(stdin);
scanf("%c", & resp);
} while (resp != 's');
}
main() {
struct disciplinas curso[5];
struct registro alunos[3];
struct grade m_Salva[4][5];
int escolha;
curso[0].codigo = 122;
strcpy(curso[0].nome, "Algoritimos");
curso[0].c_Horaria = 60;
strcpy(curso[0].h_Semanal, "Segunda bloco 1 e terca bloco 2");
curso[1].codigo = 127;
strcpy(curso[1].nome, "Estrutura de dados");
curso[1].c_Horaria = 60;
strcpy(curso[1].h_Semanal, "terca bloco 3 e quarta bloco 4");
curso[2].codigo = 132; //dados salvos
strcpy(curso[2].nome, "Sistemas Operacionais A ");
curso[2].c_Horaria = 60;
strcpy(curso[2].h_Semanal, "Terca bloco 3 e Quinta bloco 2");
curso[3].codigo = 143;
strcpy(curso[3].nome, "Padroes de Projeto");
curso[3].c_Horaria = 30;
strcpy(curso[3].h_Semanal, "Sexta bloco 2");
curso[4].codigo = 135;
strcpy(curso[4].nome, "Banco de dados ll");
curso[4].c_Horaria = 60;
strcpy(curso[4].h_Semanal, "Quarta bloco 3 e sexta bloco 2");
do {
printf("\n\n");
printf(" -----------------------\n");
printf(" ------Bem Vindo!!------\n");
printf(" -----------------------\n");
printf("Escolha uma das opcoes abaixo\n");
printf("1. Adicionar aluno\n");
printf("2. Consultar aluno\n");
printf("3. Sair\n");
scanf("%d", & escolha);
if (escolha == 1) {
add_Aluno(alunos, curso, m_Salva);
} else if (escolha == 2) {
consulta(alunos, m_Salva);
}
} while (escolha != 3);
}