Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- typedef struct agenda { //Define estrutura para cadastrar livro.
- char nome[40], data[10];
- int paginas;
- } agenda;
- FILE *arq;
- int option;
- void menu() //Menu.
- {
- setlocale(LC_ALL,"Portuguese");
- printf("Cadastro de Agenda de Leitura\n");
- printf("Opções:\n");
- printf("1 - Inclusão\n");
- printf("2 - Alteração\n");
- printf("3 - Exclusão\n");
- printf("4 - Listar Agenda\n");
- printf("5 - Sair\n");
- printf("Digite a opção desejada: "); scanf("%d",&option);
- while(!((option==1)||(option==2)||(option==3)||(option==4)||(option==5))){ //Verifica se opção é válida.
- printf("Opção invalida, Insira a opção desejada: ");
- scanf("%d",&option);
- }
- menu_options();
- }
- void cls() //Limpa a tela.
- {
- system("cls");
- }
- void retorna_menu() //Retorna ao Menu Principal.
- {
- cls();
- menu();
- }
- void menu_options()
- {
- cls();
- if (option == 1)
- {
- FILE *arq = fopen("Agenda.txt", "a");
- printf("Inclusão\n");
- struct agenda novo;
- printf("Digite o nome do título: ");
- fflush(stdin);
- gets(novo.nome);
- printf("Número de paginas: ");
- fflush(stdin);
- scanf("%d",&novo.paginas);
- printf("Digite o data no formato DD/MM/AAA: ");
- fflush(stdin);
- gets(novo.data);
- fwrite(&novo, sizeof(struct agenda), 1, arq);
- fclose(arq);
- retorna_menu();
- }
- else if (option == 2)
- {
- printf("Alteração\n");
- FILE *arq = fopen("Agenda.txt", "r");
- fclose(arq);
- }
- else if (option == 3)
- {
- printf("Exclusão");
- }
- else if (option == 4)
- {
- struct agenda listar;
- printf("Listar Agenda\n");
- arq = fopen("Agenda.txt", "r");
- while(fread(&listar,sizeof(struct agenda),1,arq))
- {
- printf("Nome: %s\n",listar.nome);
- printf("Paginas: %d\n",listar.paginas);
- printf("Data: %s\n\n",listar.data);
- }
- fclose(arq);
- }
- else exit(0);
- }
- int main()
- {
- menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement