Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. typedef struct {
  2. char nome[25];
  3. int matricula;
  4. float notas[2];
  5. char situacao[10];
  6. } Aluno;
  7.  
  8. Aluno Alunos[N_ALUNOS];
  9.  
  10. int alunosCadastrados = 0;
  11.  
  12. void atualizaArray(int posExcluida){
  13. // Se a posição excluida não for a última
  14. if(posExcluida < alunosCadastrados - 1){
  15. // Percorre todo vetor
  16. for(int j = 0; j < alunosCadastrados; j++){
  17. // se o índice atual for maior que a posição excluida do vetor
  18. if(j > posExcluida){
  19. Alunos[j - 1].matricula = Alunos[j].matricula;
  20. strcpy(Alunos[j - 1].situacao, Alunos[j].situacao);
  21. Alunos[j - 1].notas[0] = Alunos[j].notas[0];
  22. Alunos[j - 1].notas[1] = Alunos[j].notas[1];
  23. strcpy(Alunos[j - 1].nome, Alunos[j].nome);
  24. }
  25. }
  26. }
  27. }
  28.  
  29. alunosCadastrados--;
  30.  
  31. for (int i = 0;i < alunosCadastrados;i++){
  32. // ^^^^^^^^^^^^^^^^^^^^
  33.  
  34. void atualizaArray(int posExcluida){
  35. if(posExcluida >= 0 && posExcluida < alunosCadastrados - 1){
  36. for(int j = posExcluida; j < alunosCadastrados - 1; j++){
  37. // ^--- começa na posExcluida ^--- termina uma antes do fim
  38. Alunos[j].matricula = Alunos[j + 1].matricula;
  39. strcpy(Alunos[j - 1].situacao, Alunos[j + 1].situacao);
  40. Alunos[j].notas[0] = Alunos[j + 1].notas[0];
  41. Alunos[j].notas[1] = Alunos[j + 1].notas[1];
  42. strcpy(Alunos[j].nome, Alunos[j + 1].nome);
  43. }
  44. }
  45. alunosCadastrados--; //ajustar o tamanho
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement