Guest User

Untitled

a guest
Nov 25th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //STRUCT
  4. struct pessoas {
  5.  
  6. char nome [20];
  7. char email [20];
  8. char endereco [20];
  9. char telefone [10];
  10. char aniversario [10];
  11.  
  12. };
  13.  
  14. //VARIAVEIS GLOBAIS
  15. struct pessoas p;
  16.  
  17.  
  18. void cadastrar(FILE *f);
  19. void consultanome(FILE *f);
  20. void consultemail (FILE *f);
  21. void exclusao(FILE *f);
  22. void alteracao(FILE *f);
  23. void impressao(FILE*f);
  24.  
  25.  
  26. void main(void){
  27. int op;
  28. FILE *f;
  29.  
  30. do{
  31. printf(" MENU AGENDA \n\n");
  32. printf(" 1- Cadastro \n");
  33. printf(" 2- Consulta por nome\n");
  34. printf(" 3- Conculta por email\n");
  35. printf(" 4-Exclusao \n");
  36. printf(" 5- Alteracao\n");
  37. printf(" 6-Impressao \n");
  38.  
  39. printf("Escolha uma op:");
  40. scanf("%i", &op);
  41. switch(op){
  42.  
  43. case 1:{
  44. system("cls");
  45. cadastrar(f);
  46. break;
  47. }
  48.  
  49. case 2:{
  50. system("cls");
  51. consultanome(f);
  52. break;
  53. }
  54.  
  55. case 3:{
  56. system("cls");
  57. consultemail(f);
  58. break;
  59. }
  60. case 4:{
  61. system("cls");
  62. exclusao(f);
  63. break;
  64. }
  65.  
  66. case 5:{
  67. system("cls");
  68. alterar(f);
  69. break;
  70. }
  71.  
  72. case 6:{
  73. system("cls");
  74. impressao(f);
  75. break;}
  76. default:
  77. printf("Saindo!\n");
  78. }
  79.  
  80. }while(op != 6);
  81. system("pause");
  82. }
  83.  
  84. //FUNÇÕES
  85. void cadastrar(FILE*f){
  86.  
  87. f = fopen("arquivo.txt", "a+");
  88.  
  89. printf("--- TELA DE CADASTRO ---\n\n");
  90.  
  91. printf("Digite seu nome:");
  92. fflush(stdin);
  93. gets(p.nome);
  94.  
  95. printf("Digite seu email:");
  96. fflush(stdin);
  97. gets(p.email);
  98.  
  99. printf("Digite seu endereco:");
  100. fflush(stdin);
  101. gets(p.endereco);
  102.  
  103. printf("Digite seu Telefone:");
  104. fflush(stdin);
  105. gets(p.telefone);
  106.  
  107. printf("Digite do seu aniversario");
  108. fflush(stdin);
  109. gets(p.aniversario);
  110.  
  111.  
  112. fprintf(f, "\n------------------------");
  113. fprintf(f,"\nNome:%s", p.nome);
  114. fprintf(f, "\nEmail:%s", p.email);
  115. fprintf(f, "\nEndereco:%s", p.endereco);
  116. fprintf(f,"\nTelefone:%s",p.telefone);
  117. fprintf(f,"\nAniversario:%s",p.aniversario);
  118. fclose(f);
  119. system("cls");
  120. main();
  121. }
  122.  
  123. void consultanome(FILE*f){
  124. char nome [20];
  125. fflush(stdin);
  126. f = fopen("arquivo.txt", "r");
  127.  
  128. if (f == NULL)
  129. {
  130. printf("ERRO! O arquivo não foi aberto!\n");
  131. }
  132. else
  133. {
  134. printf("\n----------------------------------------------------------\n\n");
  135. printf("Digite o nome para pesquisar: ");
  136. gets(nome);
  137. printf("\n");
  138. }
  139. fclose(f);
  140. main ();
  141. }
  142.  
  143. void consultemail(FILE*f){
  144. char email [20];
  145. fflush(stdin);
  146. f = fopen("arquivo.txt", "r");
  147.  
  148. if (f == NULL)
  149. {
  150. printf("ERRO! O arquivo não foi aberto!\n");
  151. }
  152. else
  153. {
  154. printf("\n----------------------------------------------------------\n\n");
  155. printf("Digite o email para pesquisar: ");
  156. gets(email);
  157. printf("\n");
  158. }
  159. fclose(f);
  160. main ();
  161. }
  162.  
  163. void exclusao(FILE*f){
  164. int op=0;
  165.  
  166. do{
  167. remove("arquivo.txt");
  168. fprintf(f,"\nNome:%s", p.nome);
  169. fprintf(f, "\nEmail:%s", p.email);
  170. fprintf(f, "\nEndereco:%s", p.endereco);
  171. fprintf(f,"\nTelefone:%s",p.telefone);
  172. fprintf(f,"\nAniversario:%s",p.aniversario);
  173. fclose(f);
  174. scanf("%d", &op);
  175.  
  176.  
  177. }while(op != 0);
  178. fclose(f);
  179. main ();
  180.  
  181. }
  182.  
  183. void alteracao(FILE*f){
  184. f=fopen("arquivo.dat","r+b");
  185. int num;
  186.  
  187. if(f==NULL){
  188. printf ("Erro ao abrir o arquivo.\n");
  189. return;
  190. }
  191.  
  192. system ("cls");
  193. printf ("\t\t\tMODIFICAR ELEMENTO\n\n");
  194. printf ("\nEscolha o numero da opcao que deseja modificar.\n\n");
  195. printf (" 1-Cadastro");
  196.  
  197. switch(num){
  198. case 1: printf ("Cadastro:\n ");
  199. break;
  200. default: printf ("Numero invalido, digite novamente.\n\n");
  201.  
  202. }
  203. }
  204.  
  205. void impressao(FILE*f){
  206.  
  207. fflush(stdin);
  208. f = fopen("arquivo.txt", "r");
  209.  
  210. if (f == NULL)
  211. {
  212. printf("ERRO! O arquivo não foi aberto!\n");
  213. }
  214. else
  215. {
  216.  
  217. printf("\n");
  218. }
  219. fclose(f);
  220. main ();
  221. }
Advertisement
Add Comment
Please, Sign In to add comment