Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //STRUCT
- struct pessoas {
- char nome [20];
- char email [20];
- char endereco [20];
- char telefone [10];
- char aniversario [10];
- };
- //VARIAVEIS GLOBAIS
- struct pessoas p;
- void cadastrar(FILE *f);
- void consultanome(FILE *f);
- void consultemail (FILE *f);
- void exclusao(FILE *f);
- void alteracao(FILE *f);
- void impressao(FILE*f);
- void main(void){
- int op;
- FILE *f;
- do{
- printf(" MENU AGENDA \n\n");
- printf(" 1- Cadastro \n");
- printf(" 2- Consulta por nome\n");
- printf(" 3- Conculta por email\n");
- printf(" 4-Exclusao \n");
- printf(" 5- Alteracao\n");
- printf(" 6-Impressao \n");
- printf("Escolha uma op:");
- scanf("%i", &op);
- switch(op){
- case 1:{
- system("cls");
- cadastrar(f);
- break;
- }
- case 2:{
- system("cls");
- consultanome(f);
- break;
- }
- case 3:{
- system("cls");
- consultemail(f);
- break;
- }
- case 4:{
- system("cls");
- exclusao(f);
- break;
- }
- case 5:{
- system("cls");
- alterar(f);
- break;
- }
- case 6:{
- system("cls");
- impressao(f);
- break;}
- default:
- printf("Saindo!\n");
- }
- }while(op != 6);
- system("pause");
- }
- //FUNÇÕES
- void cadastrar(FILE*f){
- f = fopen("arquivo.txt", "a+");
- printf("--- TELA DE CADASTRO ---\n\n");
- printf("Digite seu nome:");
- fflush(stdin);
- gets(p.nome);
- printf("Digite seu email:");
- fflush(stdin);
- gets(p.email);
- printf("Digite seu endereco:");
- fflush(stdin);
- gets(p.endereco);
- printf("Digite seu Telefone:");
- fflush(stdin);
- gets(p.telefone);
- printf("Digite do seu aniversario");
- fflush(stdin);
- gets(p.aniversario);
- fprintf(f, "\n------------------------");
- fprintf(f,"\nNome:%s", p.nome);
- fprintf(f, "\nEmail:%s", p.email);
- fprintf(f, "\nEndereco:%s", p.endereco);
- fprintf(f,"\nTelefone:%s",p.telefone);
- fprintf(f,"\nAniversario:%s",p.aniversario);
- fclose(f);
- system("cls");
- main();
- }
- void consultanome(FILE*f){
- char nome [20];
- fflush(stdin);
- f = fopen("arquivo.txt", "r");
- if (f == NULL)
- {
- printf("ERRO! O arquivo não foi aberto!\n");
- }
- else
- {
- printf("\n----------------------------------------------------------\n\n");
- printf("Digite o nome para pesquisar: ");
- gets(nome);
- printf("\n");
- }
- fclose(f);
- main ();
- }
- void consultemail(FILE*f){
- char email [20];
- fflush(stdin);
- f = fopen("arquivo.txt", "r");
- if (f == NULL)
- {
- printf("ERRO! O arquivo não foi aberto!\n");
- }
- else
- {
- printf("\n----------------------------------------------------------\n\n");
- printf("Digite o email para pesquisar: ");
- gets(email);
- printf("\n");
- }
- fclose(f);
- main ();
- }
- void exclusao(FILE*f){
- int op=0;
- do{
- remove("arquivo.txt");
- fprintf(f,"\nNome:%s", p.nome);
- fprintf(f, "\nEmail:%s", p.email);
- fprintf(f, "\nEndereco:%s", p.endereco);
- fprintf(f,"\nTelefone:%s",p.telefone);
- fprintf(f,"\nAniversario:%s",p.aniversario);
- fclose(f);
- scanf("%d", &op);
- }while(op != 0);
- fclose(f);
- main ();
- }
- void alteracao(FILE*f){
- f=fopen("arquivo.dat","r+b");
- int num;
- if(f==NULL){
- printf ("Erro ao abrir o arquivo.\n");
- return;
- }
- system ("cls");
- printf ("\t\t\tMODIFICAR ELEMENTO\n\n");
- printf ("\nEscolha o numero da opcao que deseja modificar.\n\n");
- printf (" 1-Cadastro");
- switch(num){
- case 1: printf ("Cadastro:\n ");
- break;
- default: printf ("Numero invalido, digite novamente.\n\n");
- }
- }
- void impressao(FILE*f){
- fflush(stdin);
- f = fopen("arquivo.txt", "r");
- if (f == NULL)
- {
- printf("ERRO! O arquivo não foi aberto!\n");
- }
- else
- {
- printf("\n");
- }
- fclose(f);
- main ();
- }
Advertisement
Add Comment
Please, Sign In to add comment