fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #define max 100
  4. #define erro -1
  5.  
  6. typedef int chave;
  7.  
  8. typedef struct
  9. {
  10. chave chav;
  11. }reg;
  12.  
  13. typedef struct
  14. {
  15. reg a[max];
  16. int tamanho;
  17. }lista;
  18.  
  19. int criar_lista (lista *list)
  20. {
  21. list->tamanho=0;
  22. printf("Lista criada");
  23. }
  24.  
  25. int insere_empura (lista *list, chave i, int j)
  26. {
  27. int k;
  28. for(k=list->tamanho;k>j;k--)
  29. list->a[k] = list->a[k-1];
  30. list->a[j].chav = i;
  31. }
  32.  
  33. int exibir_lista (lista list)
  34. {
  35. int k;
  36. printf("\n");
  37. for(k=0;k<list.tamanho;k++)
  38. printf("%i ",list.a[k].chav);
  39. }
  40.  
  41. int main()
  42. {
  43. lista lista_1;
  44. int i,j,n;
  45. srand((unsigned)time(NULL));
  46. printf("Insira o tamanho da lista: ");
  47. scanf("%i",&n);
  48. criar_lista(&lista_1);
  49. printf("\n\nInsira os %i elementos da lista\n",n);
  50. for(i=0;i<n;i++)
  51. printf("Insira o %i elemento: ",i+1);
  52. scanf("%i",&j);
  53. insere_empura(&lista_1,j,rand()%lista_1->tamanho);
  54. i++;
  55. exibir_lista(lista_1);
  56. }
  57. }
  58.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
1
2
3
4
5
compilation info
prog.c: In function ‘main’:
prog.c:45:2: warning: implicit declaration of function ‘srand’ [-Wimplicit-function-declaration]
  srand((unsigned)time(NULL));
  ^~~~~
prog.c:50:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
  for(i=0;i<n;i++)
  ^~~
prog.c:52:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘for’
   scanf("%i",&j);
   ^~~~~
prog.c:53:28: warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration]
   insere_empura(&lista_1,j,rand()%lista_1->tamanho);
                            ^~~~
prog.c:53:42: error: invalid type argument of ‘->’ (have ‘lista {aka struct <anonymous>}’)
   insere_empura(&lista_1,j,rand()%lista_1->tamanho);
                                          ^~
prog.c: At top level:
prog.c:57:1: error: expected identifier or ‘(’ before ‘}’ token
 }
 ^
prog.c: In function ‘criar_lista’:
prog.c:23:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function ‘insere_empura’:
prog.c:31:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function ‘exibir_lista’:
prog.c:39:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty