Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4.  
  5. typedef struct agenda { //Define estrutura para cadastrar livro.
  6.     char nome[40], data[10];
  7.     int paginas;
  8. } agenda;
  9.  
  10. FILE *arq;
  11. int option;
  12.  
  13. void menu() //Menu.
  14. {
  15.     setlocale(LC_ALL,"Portuguese");
  16.     printf("Cadastro de Agenda de Leitura\n");
  17.     printf("Opções:\n");
  18.     printf("1 - Inclusão\n");
  19.     printf("2 - Alteração\n");
  20.     printf("3 - Exclusão\n");
  21.     printf("4 - Listar Agenda\n");
  22.     printf("5 - Sair\n");
  23.     printf("Digite a opção desejada: "); scanf("%d",&option);
  24.  
  25.     while(!((option==1)||(option==2)||(option==3)||(option==4)||(option==5))){ //Verifica se opção é válida.
  26.         printf("Opção invalida, Insira a opção desejada: ");
  27.         scanf("%d",&option);
  28.     }
  29.     menu_options();
  30.  
  31. }
  32. void cls() //Limpa a tela.
  33. {
  34.     system("cls");
  35. }
  36. void retorna_menu() //Retorna ao Menu Principal.
  37. {
  38.     cls();
  39.     menu();
  40. }
  41. void menu_options()
  42. {
  43.     cls();
  44.     if (option == 1)
  45.     {
  46.         FILE *arq = fopen("Agenda.txt", "a");
  47.         printf("Inclusão\n");
  48.         struct agenda novo;
  49.         printf("Digite o nome do título: ");
  50.         fflush(stdin);
  51.         gets(novo.nome);
  52.         printf("Número de paginas: ");
  53.         fflush(stdin);
  54.         scanf("%d",&novo.paginas);
  55.         printf("Digite o data no formato DD/MM/AAA: ");
  56.         fflush(stdin);
  57.         gets(novo.data);
  58.         fwrite(&novo, sizeof(struct agenda), 1, arq);
  59.         fclose(arq);
  60.         retorna_menu();
  61.  
  62.     }
  63.     else if (option == 2)
  64.     {
  65.         printf("Alteração\n");
  66.         FILE *arq = fopen("Agenda.txt", "r");
  67.  
  68.         fclose(arq);
  69.     }
  70.     else if (option == 3)
  71.     {
  72.         printf("Exclusão");
  73.     }
  74.     else if (option == 4)
  75.     {
  76.         struct agenda listar;
  77.         printf("Listar Agenda\n");
  78.         arq = fopen("Agenda.txt", "r");
  79.         while(fread(&listar,sizeof(struct agenda),1,arq))
  80.         {
  81.             printf("Nome: %s\n",listar.nome);
  82.             printf("Paginas: %d\n",listar.paginas);
  83.             printf("Data: %s\n\n",listar.data);
  84.         }
  85.         fclose(arq);
  86.     }
  87.     else exit(0);
  88. }
  89.  
  90. int main()
  91. {
  92.     menu();
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement