kalo93

Untitled

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