fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef int identificador;
  5.  
  6. typedef struct {
  7. identificador matricula;
  8. char nome[10];
  9. int idade;
  10. } aluno;
  11.  
  12. int i = 0;
  13. aluno vAluno[100];
  14.  
  15. void inserir() {
  16.  
  17. char flag;
  18.  
  19. do {
  20.  
  21. printf("-----------------------------\n");
  22.  
  23. printf("Digite a Matrícula: ");
  24. scanf("%d", &vAluno[i].matricula);
  25.  
  26. printf("Digite o nome: ");
  27. scanf("%s", vAluno[i].nome);
  28.  
  29. printf("Digite a idade: ");
  30. scanf("%d", &vAluno[i].idade);
  31.  
  32. printf("-----------------------------\n");
  33. printf("Deseja Inserir Outro Registro (S/N)? ");
  34. scanf(" %c", &flag);
  35. i++;
  36.  
  37. } while(flag != 'N');
  38.  
  39. }
  40.  
  41. void listar() {
  42. int k;
  43. printf("------------------------------------------------\n");
  44. printf("%-5s %-15s %-15s %-10s\n", "#", "MATRICULA", "NOME", "IDADE");
  45.  
  46. for(k=0; k<i; k++) {
  47. printf("%-5d %-15d %-15s %-10d\n", (k+1), vAluno[k].matricula, vAluno[k].nome, vAluno[k].idade);
  48.  
  49.  
  50. }
  51. printf("------------------------------------------------\n");
  52. }
  53.  
  54. void menu_de_opcoes() {
  55.  
  56. int opcao;
  57.  
  58. do {
  59.  
  60. printf("\n--------O P Ç Õ E S----------\n");
  61. printf("1 - Inserir\n");
  62. printf("2 - Listar\n");
  63. printf("3 - Ordenar\n");
  64. printf("0 - Sair\n");
  65.  
  66. printf("Selecione uma opção: ");
  67. scanf(" %d", &opcao);
  68.  
  69. switch(opcao) {
  70. case 1: inserir(); break;
  71. case 2: listar(); break;
  72. case 3: menu_ordenar(); break;
  73.  
  74. }
  75.  
  76.  
  77. } while(opcao != 0);
  78.  
  79. }
  80.  
  81. void menu_ordenar() {
  82.  
  83. int opcao;
  84.  
  85. do {
  86.  
  87. printf("\n--------Escolha a opcao de ordenacao----------\n");
  88. printf("1 - Método da Bolha\n");
  89. printf("2 - Ordenação por Seleção\n");
  90. printf("3 - Ordenação por Inserção \n");
  91. printf("0 - Sair\n");
  92.  
  93. printf("Selecione uma opção: ");
  94. scanf(" %d", &opcao);
  95.  
  96. switch(opcao) {
  97. case 1: inserir(); break;
  98. case 2: listar(); break;
  99. case 3: ordenar(); break;
  100.  
  101. }
  102.  
  103.  
  104. } while(opcao != 0);
  105.  
  106. }
  107.  
  108. void bubleSort( aluno* v, int tam) {
  109. int i, j;
  110.  
  111. for (i = 1; i < tam; i++) {
  112.  
  113. for (j = 0; j < tam-1; j++) {
  114.  
  115. if (v[j].matricula > v[j+1].matricula)
  116. troca(&v[j], &v[j+1]);
  117.  
  118. }
  119. }
  120. }
  121.  
  122. void troca(aluno* n1, aluno* n2) {
  123. aluno aux;
  124.  
  125. aux = *n1;
  126. *n1 = *n2;
  127. *n2 = aux;
  128. }
  129.  
  130. int main(int argc, char *argv[]) {
  131.  
  132. menu_de_opcoes();
  133.  
  134. return 0;
  135. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'menu_de_opcoes':
prog.c:74:12: warning: implicit declaration of function 'menu_ordenar' [-Wimplicit-function-declaration]
    case 3: menu_ordenar(); break; 
            ^
prog.c: At top level:
prog.c:83:6: warning: conflicting types for 'menu_ordenar'
 void menu_ordenar() {
      ^
prog.c:74:12: note: previous implicit declaration of 'menu_ordenar' was here
    case 3: menu_ordenar(); break; 
            ^
prog.c: In function 'menu_ordenar':
prog.c:101:12: warning: implicit declaration of function 'ordenar' [-Wimplicit-function-declaration]
    case 3: ordenar(); break; 
            ^
prog.c: In function 'bubleSort':
prog.c:118:12: warning: implicit declaration of function 'troca' [-Wimplicit-function-declaration]
            troca(&v[j], &v[j+1]);
            ^
prog.c: At top level:
prog.c:124:6: warning: conflicting types for 'troca'
 void troca(aluno* n1, aluno* n2) {
      ^
prog.c:118:12: note: previous implicit declaration of 'troca' was here
            troca(&v[j], &v[j+1]);
            ^
/home/UY5SmL/cct5XTtS.o: In function `menu_ordenar':
prog.c:(.text+0x221): undefined reference to `ordenar'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty