kalo93

Untitled

Feb 4th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6. #define MAX 200
  7.  
  8. typedef struct cel{
  9. int cod;
  10. char nome[MAX];
  11. char cc[MAX];
  12. struct cel *prox;
  13. }celula;
  14.  
  15. celula *ini = NULL;
  16.  
  17. void imprima( )
  18. {
  19. system("cls");
  20. if (ini == NULL)
  21. {
  22. printf("\nLista vazia.\n");
  23. getch();
  24. return;
  25. }
  26. celula *p;
  27. printf("\n Itens na lista: ");
  28. for (p = ini; p != NULL; p = p->prox)
  29. printf( "%d ", p->cod);
  30. printf( "%d ", p->nome);
  31. getch();
  32. }
  33.  
  34. celula *busca(celula *ini)
  35. {
  36. system("cls");
  37. int x=0;
  38. printf("numero");
  39. scanf("%d",&x);
  40. celula *p;
  41. p = ini->prox;
  42. while (p != NULL && p->cod != x)
  43. p=p->prox;
  44. return p;
  45. }
  46.  
  47. void insere()
  48. {
  49. system("cls");
  50. int x;
  51. char cc[MAX];
  52. char nome(MAX);
  53. printf("numero: ");
  54. scanf("%d",&x);
  55. celula *nova = (celula*)malloc (sizeof (celula));
  56. nova->cod = x;
  57.  
  58. printf("nome: ");
  59. scanf("%s",&nome);
  60. nova->nome[MAX]= nome;
  61.  
  62. printf("codigo de cidadão: ");
  63. scanf("%s",&cc);
  64. nova->cc[MAX]= cc;
  65.  
  66. nova->prox = ini;
  67. ini = nova;
  68.  
  69. printf("numero %d inserido.\n",x);
  70. getch();
  71. }
  72.  
  73. void remove()
  74. {
  75. if (ini == NULL)
  76. {
  77. printf("\nLista vazia. Sem itens para remover.\n");
  78. getch();
  79. return;
  80. }
  81.  
  82. else
  83. {
  84. celula *remove = ini;
  85. ini = remove->prox;
  86. printf("\nitem %d removido.\n",remove->cod);
  87. free(remove);
  88. getch();
  89. }
  90. }
  91.  
  92. void menu() {
  93. system("cls");
  94. printf(" Menu ");
  95. printf("\n*********************************");
  96. printf("\n* 1-Inserir *");
  97. printf("\n* 2-Listar *");
  98. printf("\n* 3-buscar *");
  99. printf("\n* 4-remove *");
  100. printf("\n* 5-alterar *");
  101. printf("\n* 6-inserir no fim *");
  102. printf("\n* 0-sair *");
  103. printf("\n*********************************\n");
  104. printf("Entre com a opcao desejada: ");
  105. }
  106.  
  107. int main(){
  108. char op;
  109. do {
  110. menu();
  111. op=getche();
  112. switch(op) {
  113. case '1': insere();
  114. break;
  115. case '2': imprima();
  116. break;
  117. case '3': busca(ini);
  118. break;
  119. case '4': remove();
  120. break;
  121.  
  122. }
  123.  
  124. } while (op != '0');
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment