kalo93

Untitled

Feb 4th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 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. printf("Lista de pacientes");
  23. printf("***************************");
  24. celula *p;
  25. if (ini == NULL)
  26. {
  27. printf("\nLista vazia.\n");
  28. getch();
  29. return;
  30. }
  31.  
  32. for (p = ini; p != NULL; p = p->prox){
  33. printf( "\n\nCó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("****************************************");
  39. }
  40. getch();
  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 alterar( )
  65. {
  66. system("cls");
  67. int x;
  68. printf("numero: ");
  69. scanf("%d",&x);
  70. celula *p;
  71. p = ini;
  72. while (p != NULL && p->cod != x)
  73. p=p->prox;
  74. if (p == NULL){
  75. printf("\nvalor %d nao encontrado.",x);
  76. getch();
  77. return;
  78.  
  79. }
  80. printf("valor encontrado: %d",p->cod);
  81. printf("%s",p->nome);
  82. getch();
  83. }
  84.  
  85. void insere()
  86. {
  87. int x;
  88. celula *nova = (celula*)malloc (sizeof (celula));
  89. system("cls");
  90. printf(" utente ");
  91. printf("\n************************************");
  92. printf("\nnumero: ");
  93. scanf("%d",&x);
  94. //o apontador aponta para o cod da estrutura que fica com o valor de x e das restantes
  95.  
  96. nova->cod = x;
  97. printf("nome:");
  98. scanf("%s",nova->nome);
  99. printf("Cartão de Cidadão:");
  100. scanf("%s",nova->cc);
  101. printf("data:");
  102. scanf("%s",nova->date);
  103. nova->prox = ini;
  104. ini = nova;
  105. printf("numero %d inserido.\n",x);
  106. printf("************************************");
  107. getch();
  108. system("cls");
  109. }
  110.  
  111. void remove_cel()
  112. {
  113. if (ini == NULL)
  114. {
  115. printf("\nLista vazia.\n");
  116. getch();
  117. return;
  118. }
  119.  
  120. else
  121. {
  122. celula *remove = ini;
  123. ini = remove->prox;
  124. printf("\nitem %d removido.\n",remove->cod);
  125. free(remove);
  126. getch();
  127. }
  128. }
  129.  
  130. void menu() {
  131. system("cls");
  132. printf(" Menu ");
  133. printf("\n*********************************");
  134. printf("\n* 1-Inserir *");
  135. printf("\n* 2-Listar *");
  136. printf("\n* 3-buscar *");
  137. printf("\n* 4-remover ultimo paciente *");
  138. printf("\n* 5-alterar *");
  139. printf("\n* 6-inserir no fim *");
  140. printf("\n* 0-sair *");
  141. printf("\n*********************************\n");
  142. printf("Entre com a opcao desejada: ");
  143.  
  144. }
  145.  
  146. int main(){
  147. setlocale(LC_ALL, "Portuguese");
  148. char op;
  149. do {
  150. menu();
  151. op=getchar();
  152. switch(op) {
  153. case '1': insere();
  154. break;
  155. case '2': lista();
  156. break;
  157. case '3': busca();
  158. break;
  159. case '4': remove_cel();
  160. break;
  161. case '5': alterar();
  162. break;
  163. }
  164.  
  165. } while (op != '0');
  166.  
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment