kalo93

Untitled

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