print a string array

Asked

Viewed 457 times

1

When I do a print on my string matrix a symbol is appearing and not the words. The matrix is located in the void query function. I put all the code because it might be a mistake somewhere else but I can’t find it.

The exercise calls for this.

•When associating a student to a discipline, check if the necessary time blocks are available in the student’s grade, if yes, associate the discipline, but show a message stating the conflict. For example, if the student is already associated with a course that takes place on Tuesday at 13, it will not be possible to add another discipline that takes place on the same day and time. See Table 1, subjects 0127 and 0132. • When entering the students' email, validate if the email is correct: to. Email must have: 3 more characters; an arroba sign (@); another 3 characters or more; followed by a endpoint sign (.); and a set of at least 2 characters;

• Allow students to consult by name or part of the name. By finding, allow to see your data and your schedule. • Example, student Peter must be found with "Ped" (from 3 characters);

• Subject information is stored in the subject list; student information is stored in the student list. Make a link, as seen in class, between them, do not duplicate the data.

Below the code is as should be presented. the code was a bit messy because n 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);
}
  • The code you put in is quite extensive. The ideal would be to put only the part that has the problem, and in particular explain which part is not working properly, because printing the matrix is a little vague.

  • I got it. Thank you. I put all the code because it could be a mistake in another function, as I haven’t found the error yet maybe someone could have seen it. But I made a few edits on my question.

1 answer

0

I suggest instead of simply using the gets, use the fgets(nome_string, tamanho_string, stdin). To print string, try using the function puts (nome_string).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.