kalo93

Untitled

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