Advertisement
kalo93

Untitled

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