kalo93

Untitled

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