kalo93

Untitled

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