kalo93

Untitled

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