Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio2.h>
- #include <time.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #define X_I 1
- #define Y_I 1
- #define X_F 80
- #define Y_F 20
- struct TpPalavra
- {
- char port[30], ing[30], significado[100];
- int pont, status;
- };
- struct TpData
- {
- int dia, mes, ano;
- };
- struct TpPessoa
- {
- char nome[40], login[10];
- int senha, pont, status;
- TpData Data;
- };
- struct TpPalavForca
- {
- char Palavra[30], Login[10];
- int Acertou;
- };
- void Quadro()
- {
- int i;
- textcolor(14);
- gotoxy(X_I,Y_I);
- printf("%c",201);
- gotoxy(X_F,Y_I);
- printf("%c",187);
- gotoxy(X_I,Y_F);
- printf("%c",200);
- gotoxy(X_F,Y_F);
- printf("%c",188);
- for(i = X_I + 1; i < X_F; i++)
- {
- gotoxy(i, Y_I);
- printf("%c", 205);
- gotoxy(i, Y_F);
- printf("%c", 205);
- }
- for(i = Y_I + 1; i < Y_F; i++)
- {
- gotoxy(X_I, i);
- printf("%c", 186);
- gotoxy(X_F, i);
- printf("%c", 186);
- }
- textcolor(15);
- }
- void QuadroFlexivel(int XI, int YI, int XF, int YF)
- {
- int i;
- textcolor(14);
- gotoxy(XI, YI);
- printf("%c",201);
- gotoxy(XF, YI);
- printf("%c",187);
- gotoxy(XI, YF);
- printf("%c",200);
- gotoxy(XF, YF);
- printf("%c",188);
- for(i = XI + 1; i < XF; i++)
- {
- gotoxy(i, YI);
- printf("%c", 205);
- gotoxy(i, YF);
- printf("%c", 205);
- }
- for(i = YI + 1; i < YF; i++)
- {
- gotoxy(XI, i);
- printf("%c", 186);
- gotoxy(XF, i);
- printf("%c", 186);
- }
- }
- void Cabecalho(char Titulo[100])
- {
- Quadro();
- textcolor(15);
- gotoxy(30, 2);
- printf("%s\n", Titulo);
- textcolor(14);
- for(int i = 2; i <= 79; i++)
- {
- gotoxy(i, 3);
- printf("%c", 205);
- }
- textcolor(15);
- }
- void ImprimePalavra(TpPalavra Pal, int linha)
- {
- /*
- QuadroFlexivel(XI, YI, XF, YF);
- gotoxy(YI, XI + 4);
- textcolor(14);
- printf("Portugues: ");
- textcolor(15);
- printf("%s", Pal.port);
- gotoxy(YI, XI + 5);
- textcolor(14);
- printf("Ingles: ");
- textcolor(15);
- printf("%s", Pal.ing);
- */
- }
- void ImprimePessoa(TpPessoa Pes, int linha)
- {
- QuadroFlexivel(2, linha - 1, 79, linha + 4);
- gotoxy(3, linha++);
- textcolor(14);
- printf("Nome: ");
- textcolor(15);
- printf("%s", Pes.nome);
- gotoxy(3, linha);
- textcolor(14);
- printf("Login: ");
- textcolor(15);
- printf("%s", Pes.login);
- gotoxy(30, linha);
- textcolor(14);
- printf("Pontuacao: ");
- textcolor(15);
- printf("%d", Pes.pont);
- gotoxy(50, linha);
- textcolor(14);
- printf("Status: ");
- textcolor(15);
- printf("%d", Pes.status);
- linha++;
- gotoxy(3, linha);
- textcolor(14);
- printf("Data: ");
- textcolor(15);
- printf("%d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
- textcolor(15);
- }
- void RelatorioPalavras(FILE *PtrArq)
- {
- TpPalavra Pal;
- system("cls");
- QuadroFlexivel(1, 1, 25, 5);
- PtrArq = fopen("Palavra.dat", "rb");
- if(PtrArq == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- }
- fclose(PtrArq);
- getch();
- }
- int PosicaoMaiorPessoa(FILE *PtrPes, int NumR)
- {
- TpPessoa Pes;
- int Pos, i = 0;
- char MaiorNome[40];
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- strcpy(MaiorNome, Pes.login);
- Pos = 0;
- for(i = 1; i < NumR; i++)
- {
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(Pes.login, MaiorNome) > 0)
- {
- strcpy(MaiorNome, Pes.login);
- Pos = i;
- }
- }
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- return Pos * sizeof(TpPessoa);
- }
- void SelecaoDiretaPessoa(FILE *PtrPes)
- {
- int PosMaior, NumR;
- TpPessoa PesA, PesB;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- while(NumR > 0)
- {
- PosMaior = PosicaoMaiorPessoa(PtrPes, NumR);
- if(PosMaior < (NumR - 1) * sizeof(TpPessoa))
- {
- fseek(PtrPes, PosMaior, 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
- fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, PosMaior, 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- }
- NumR--;
- }
- fclose(PtrPes);
- }
- void InsercaoDiretaPessoa(FILE *PtrPes)
- {
- TpPessoa PesA, PesB;
- int NumR, Pos;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- if(NumR > 1)
- {
- Pos = NumR - 1;
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- while(Pos > 0 && stricmp(PesA.login, PesB.login) < 0)
- {
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- Pos--;
- fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- }
- }
- fclose(PtrPes);
- }
- void RelatorioPessoa(FILE *PtrPes)
- {
- int linha = 5;
- TpPessoa Pes;
- clrscr();
- QuadroFlexivel(1, 1, 80, 3);
- gotoxy(30, 2);
- printf("Relatorio de pessoas");
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- }
- else
- {
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes))
- {
- if(Pes.status == 1)
- {
- ImprimePessoa(Pes, linha);
- linha += 6;
- }
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- //printf("\n\nRelatorio finalizado\n\n");
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaPalavraPort(FILE *PtrPal, char Palavra[40])
- {
- TpPalavra Pal;
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal) && stricmp(Pal.port, Palavra) != 0)
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- if(stricmp(Palavra, Pal.port) == 0)
- return ftell(PtrPal) - sizeof(TpPalavra);
- else
- return -1;
- }
- int BuscaExaustivaPessoa(FILE *PtrPes, char login[10])
- {
- TpPessoa Pes;
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes) && (stricmp(login, Pes.login) != 0 || Pes.status == 1))
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(login, Pes.login) == 0)
- return ftell(PtrPes) - sizeof(TpPessoa);
- else
- return -1;
- }
- int BubbleSortPessoa(FILE *PtrPes)
- {
- TpPessoa PesA, PesB;
- int i, j, QntdR;
- PtrPes = fopen("Pessoa.dat", "rb+");
- fseek(PtrPes, 0, 2);
- QntdR = ftell(PtrPes) / sizeof(TpPessoa);
- while(QntdR > 0)
- {
- for(i = 0; i < QntdR - 1; i++)
- {
- fseek(PtrPes, i * sizeof(TpPessoa), 0);
- fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
- fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
- if(strcmp(PesA.login, PesB.login) > 0)
- {
- fseek(PtrPes, i * sizeof(TpPessoa), 0);
- fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
- fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
- }
- }
- QntdR--;
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaSeqIndPessoa(FILE *PtrPes, char loginChave[10])
- {
- TpPessoa Pes;
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes) && stricmp(loginChave, Pes.login) > 0)
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- if(stricmp(loginChave, Pes.login) == 0)
- return ftell(PtrPes) - sizeof(TpPessoa);
- else
- return -1;
- }
- int BuscaSentinelaPessoa(FILE *PtrPes, char loginChave[10])
- {
- FILE *PtrAux;
- int i = 0, j, NumR;
- TpPessoa Pes;
- strcpy(Pes.login, loginChave);
- fseek(PtrPes, 0, 2);
- NumR = ftell(PtrPes) / sizeof(TpPessoa);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(stricmp(Pes.login, loginChave) != 0)
- {
- i++;
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- rewind(PtrPes);
- PtrAux = fopen("Temp.dat", "ab+");
- for(j = 0; j < NumR; j++)
- {
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrAux);
- }
- fclose(PtrPes);
- fclose(PtrAux);
- remove("Pessoa.dat");
- rename("Temp.dat", "Pessoa.dat");
- if(i < NumR)
- return i * sizeof(TpPessoa);
- else
- return -1;
- }
- void ExclusaoFisicaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- char LoginAux[10];
- int Pos;
- system("cls");
- Cabecalho("Exclusao Fisica de Pessoas");
- gotoxy(2, 4);
- printf("Pessoa a ser excluida:");
- fflush(stdin);
- gets(LoginAux);
- while(strcmp(LoginAux, "\0") != 0)
- {
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- Pos = BuscaExaustivaPessoa(PtrPes, LoginAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login nao cadastrado");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 3);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- FILE *PtrTemp = fopen("Temp.dat", "ab+");
- rewind(PtrPes);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- while(!feof(PtrPes))
- {
- if(strcmp(Pes.login, LoginAux) != 0)
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrTemp);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- }
- fclose(PtrPes);
- fclose(PtrTemp);
- remove("Pessoa.dat");
- rename("Temp.dat", "Pessoa.dat");
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa excluida!");
- }
- else
- fclose(PtrPes);
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Fisica de Pessoas");
- gotoxy(2, 4);
- printf("Pessoa a ser excluida:");
- fflush(stdin);
- gets(LoginAux);
- }
- }
- getch();
- }
- void ExclusaoLogicaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- char LoginAux[10];
- system("cls");
- Cabecalho("Exclusao Logica de Pessoas");
- PtrPes = fopen("Pessoa.dat", "rb+");
- gotoxy(2, 4);
- printf("Login:");
- fflush(stdin);
- gets(LoginAux);
- while(strcmp(LoginAux, "\0") != 0)
- {
- Pos = BuscaExaustivaPessoa(PtrPes, LoginAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login nao cadastrado");
- textcolor(15);
- fclose(PtrPes);
- }
- else
- {
- gotoxy(2, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 3);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- Pes.status = 0;
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa excluida!");
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Logica de Pessoas");
- gotoxy(2, 4);
- printf("Login:");
- fflush(stdin);
- gets(LoginAux);
- }
- fclose(PtrPes);
- getch();
- }
- void ConsultaPalavras(FILE *PtrArq)
- {
- TpPalavra Pal;
- int Pos;
- system("cls");
- Cabecalho("Consulta de Palavras");
- PtrArq = fopen("Palavra.dat", "rb");
- if(PtrArq == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Palavra em portugues:");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaPalavraPort(PtrArq, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(30, 5);
- printf("Dados encontrados:");
- fseek(PtrArq, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
- ImprimePalavra(Pal, 3);
- }
- getch();
- system("cls");
- Cabecalho("Consulta de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues:");
- fflush(stdin);
- gets(Pal.port);
- }
- }
- fclose(PtrArq);
- getch();
- }
- char MenuAlteraPessoa(void)
- {
- gotoxy(3, 6);
- printf("[A] - Alterar nome");
- gotoxy(3, 7);
- printf("[B] - Alterar senha");
- gotoxy(3, 8);
- printf("[C] - Alterar data");
- gotoxy(3, 9);
- printf("[ESC] - Sair ");
- return toupper(getche());
- }
- char MenuAlteraPalavra(void)
- {
- gotoxy(3, 6);
- printf("[A] - Alterar palavra em ingles");
- gotoxy(3, 7);
- printf("[B] - Alterar pontuacao");
- gotoxy(3, 8);
- printf("[C] - Alterar significado ");
- gotoxy(3, 9);
- printf("[ESC] - Sair ");
- return toupper(getche());
- }
- void CadastraPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- system("cls");
- Cabecalho("Cadastro de Palavras");
- PtrPal = fopen("Palavra.dat", "ab+");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- if(BuscaPalavraPort(PtrPal, Pal.port) >= 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra ja cadastrada");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 5);
- printf("Palavra em ingles: ");
- fflush(stdin);
- gets(Pal.ing);
- while(strcmp(Pal.ing, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 6);
- printf("Digite uma palavra valida:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.ing);
- }
- gotoxy(2, 7);
- printf("Significado da palavra: ");
- fflush(stdin);
- gets(Pal.significado);
- while(strcmp(Pal.significado, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 8);
- printf("Digite um significado valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.significado);
- }
- gotoxy(2, 9);
- printf("Pontuacao: ");
- scanf("%d", &Pal.pont);
- while(Pal.pont <= 0)
- {
- textcolor(4);
- gotoxy(2, 10);
- printf("Digite uma pontuacao valida:");
- textcolor(15);
- scanf("%d", &Pal.pont);
- }
- Pal.status = 1;
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra cadastrada!");
- }
- getch();
- system("cls");
- Cabecalho("Cadastro de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- }
- getch();
- fclose(PtrPal);
- }
- void AlteracaoPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- char Op;
- int Pos;
- system("cls");
- Cabecalho("Alteracao de Palavras");
- PtrPal = fopen("Palavra.dat", "rb+");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaPalavraPort(PtrPal, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- Op = MenuAlteraPalavra();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- gotoxy(2, 10);
- printf("Palavra em ingles atual: %s", Pal.ing);
- gotoxy(2, 11);
- printf("Nova palavra em ingles: ");
- fflush(stdin);
- gets(Pal.ing);
- while(strcmp(Pal.ing, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma palavra valida:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.ing);
- }
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra alterada!");
- break;
- case 'B':
- gotoxy(2, 10);
- printf("Pontuacao atual: %d", Pal.pont);
- gotoxy(2, 11);
- printf("Nova pontuacao: ");
- scanf("%d", &Pal.pont);
- while(Pal.pont <= 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma pontuacao valida:");
- textcolor(15);
- scanf("%d", &Pal.pont);
- }
- textcolor(3);
- gotoxy(25, 15);
- printf("Pontuacao alterada!");
- break;
- case 'C':
- gotoxy(2, 10);
- printf("Significado atual: %s", Pal.significado);
- gotoxy(2, 11);
- printf("Novo significado: ");
- fflush(stdin);
- gets(Pal.significado);
- while(strcmp(Pal.significado, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite um significado valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pal.significado);
- }
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Significado alterado!");
- break;
- default:
- gotoxy(2, 11);
- textcolor(4);
- printf("Opcao invalida!");
- textcolor(15);
- break;
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Palavras");
- Op = MenuAlteraPalavra();
- }
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Palavras");
- gotoxy(2, 4);
- printf("Palavra em portugues: ");
- gotoxy(2, 5);
- fflush(stdin);
- gets(Pal.port);
- }
- fclose(PtrPal);
- getch();
- }
- void ExclusaoFisicaPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos;
- char PalavraAux[40];
- system("cls");
- Cabecalho("Exclusao Fisica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(PalavraAux);
- while(strcmp(PalavraAux, "\0") != 0)
- {
- PtrPal = fopen("Palavra.dat", "rb");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- Pos = BuscaPalavraPort(PtrPal, PalavraAux);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- gotoxy(2, 5);
- printf("Dados encontrados:");
- ImprimePalavra(Pal, 3);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- FILE *PtrTemp = fopen("Temp.dat", "ab+");
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal))
- {
- if(strcmp(Pal.port, PalavraAux) != 0)
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrTemp);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- }
- fclose(PtrPal);
- fclose(PtrTemp);
- remove("Palavra.dat");
- rename("Temp.dat", "Palavra.dat");
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra excluida!");
- }
- else
- fclose(PtrPal);
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Fisica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(PalavraAux);
- }
- getch();
- }
- void ExclusaoLogicaPalavra(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos;
- system("cls");
- Cabecalho("Exclusao Logica de Palavras");
- PtrPal = fopen("Palavra.dat", "rb+");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(Pal.port);
- while(strcmp(Pal.port, "\0") != 0)
- {
- Pos = BuscaPalavraPort(PtrPal, Pal.port);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Palavra inexistente");
- textcolor(15);
- fclose(PtrPal);
- }
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- gotoxy(2, 5);
- printf("Dados encontrados:");
- ImprimePalavra(Pal, 3);
- gotoxy(2, 12);
- printf("Confirma exclusao?(S/N)");
- if(toupper(getche()) == 'S')
- {
- Pal.status = 0;
- fseek(PtrPal, Pos, 0);
- fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
- textcolor(3);
- gotoxy(25, 15);
- printf("Palavra excluida!");
- }
- }
- getch();
- system("cls");
- Cabecalho("Exclusao Logica de Palavras");
- gotoxy(2, 4);
- printf("Palavra a ser excluida:");
- fflush(stdin);
- gets(Pal.port);
- }
- fclose(PtrPal);
- getch();
- }
- void CadastraPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- system("cls");
- Cabecalho("Cadastro de Pessoas");
- PtrPes = fopen("Pessoa.dat", "ab+");
- gotoxy(2, 4);
- printf("Login a ser cadastrado: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- if(BuscaExaustivaPessoa(PtrPes, Pes.login) >= 0)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login ja cadastrado");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 5);
- printf("Nome: ");
- fflush(stdin);
- gets(Pes.nome);
- while(strcmp(Pes.nome, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 6);
- printf("Digite um nome valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pes.nome);
- }
- gotoxy(2, 7);
- printf("Senha: "); textcolor(0);
- scanf("%d", &Pes.senha);
- while(Pes.senha <= 0)
- {
- textcolor(4);
- gotoxy(2, 8);
- printf("Digite uma senha valida:");
- textcolor(0);
- scanf("%d", &Pes.senha);
- }
- textcolor(15);
- gotoxy(2, 9);
- printf("Data (dd mm aaaa): ");
- scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
- while(Pes.Data.dia <= 0 || Pes.Data.mes <= 0 || Pes.Data.ano <= 0 )
- {
- textcolor(4);
- gotoxy(2, 10);
- printf("Digite uma data valida: ");
- textcolor(15);
- scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
- }
- Pes.pont = 0;
- Pes.status = 1;
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Pessoa cadastrada!");
- }
- getch();
- system("cls");
- Cabecalho("Cadastro de Pessoas");
- gotoxy(2, 4);
- printf("Login a ser cadastrado: ");
- fflush(stdin);
- gets(Pes.login);
- }
- fclose(PtrPes);
- getch();
- }
- void AlteracaoPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- char Op;
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- PtrPes = fopen("Pessoa.dat", "rb+");
- gotoxy(2, 4);
- printf("Login da pessoa a ser alterada: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login inexistente!");
- textcolor(15);
- }
- else
- {
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- Op = MenuAlteraPessoa();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- gotoxy(2, 10);
- printf("Nome atual: %s\n", Pes.nome);
- gotoxy(2, 11);
- printf("Novo nome: ");
- fflush(stdin);
- gets(Pes.nome);
- while(strcmp(Pes.nome, "\0") == 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite um nome valido:");
- fflush(stdin);
- textcolor(15);
- gets(Pes.nome);
- }
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Nome alterado!");
- break;
- case 'B':
- gotoxy(2, 10);
- printf("Senha atual: %d\n", Pes.senha);
- gotoxy(2, 11);
- printf("Nova senha: "); textcolor(0);
- scanf("%d", &Pes.senha);
- while(Pes.senha <= 0)
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma senha valida:");
- textcolor(0);
- scanf("%d", &Pes.senha);
- }
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Senha alterada!");
- break;
- case 'C':
- gotoxy(2, 10);
- printf("Data atual: %d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
- gotoxy(2, 11);
- printf("Nova data (dd mm aaaa): ");
- scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
- while(Pes.Data.dia <= 0 || Pes.Data.mes <= 0 || Pes.Data.ano <= 0 )
- {
- textcolor(4);
- gotoxy(2, 12);
- printf("Digite uma data valida: ");
- scanf("%d %d %d", &Pes.Data.dia, &Pes.Data.mes, &Pes.Data.ano);
- }
- fseek(PtrPes, Pos, 0);
- fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
- textcolor(3);
- gotoxy(25, 15);
- printf("Data alterada!");
- break;
- default:
- gotoxy(2, 11);
- textcolor(4);
- printf("Opcao invalida!");
- textcolor(15);
- break;
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- Op = MenuAlteraPessoa();
- }
- }
- getch();
- system("cls");
- Cabecalho("Alteracao de Pessoas");
- gotoxy(2, 4);
- printf("Login da pessoa a ser alterada: ");
- fflush(stdin);
- gets(Pes.login);
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaBinariaPessoa(FILE *PtrPes, char loginChave[10])
- {
- int inicio = 0, meio, fim;
- TpPessoa R;
- fseek(PtrPes, 0, 2);
- fim = ftell(PtrPes) / sizeof(TpPessoa) - 1;
- meio = fim / 2;
- fseek(PtrPes, meio * sizeof(TpPessoa), 0);
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- while(inicio < fim && strcmp(loginChave, R.login) != 0)
- {
- if(strcmp(loginChave, R.login) > 0)
- inicio = meio + 1;
- else
- fim = meio - 1;
- meio = (inicio + fim) / 2;
- fseek(PtrPes, meio * sizeof(TpPessoa), 0);
- fread(&R, sizeof(TpPessoa), 1, PtrPes);
- }
- if(strcmp(loginChave, R.login) == 0)
- return meio * sizeof(TpPessoa);
- else
- return -1;
- }
- int BuscaBinariaPalavra(FILE *PtrPal, char palavraChave[40])
- {
- TpPalavra Pal;
- int inicio = 0, meio, fim;
- fseek(PtrPal, 0, 2);
- fim = ftell(PtrPal) / sizeof(TpPalavra) - 1;
- meio = fim / 2;
- fseek(PtrPal, meio, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(inicio < fim && stricmp(palavraChave, Pal.port) != 0)
- {
- if(stricmp(palavraChave, Pal.port) > 0)
- inicio = meio + 1;
- else
- inicio = meio - 1;
- meio = (inicio + fim) / 2;
- fseek(PtrPal, meio, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- }
- if(stricmp(palavraChave, Pal.port) == 0)
- return meio * sizeof(TpPalavra);
- else
- return -1;
- }
- void ConsultaPessoa(FILE *PtrPes)
- {
- TpPessoa Pes;
- int Pos;
- system("cls");
- Cabecalho("Consulta de pessoas");
- PtrPes = fopen("Pessoa.dat", "rb");
- if(PtrPes == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de pessoas inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Login a ser procurado: ");
- fflush(stdin);
- gets(Pes.login);
- while(strcmp(Pes.login, "\0") != 0)
- {
- Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
- if(Pos == -1)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Login inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(30, 5);
- printf("Dados encontrados:");
- fseek(PtrPes, Pos, 0);
- fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
- ImprimePessoa(Pes, 3);
- }
- getch();
- system("cls");
- Cabecalho("Consulta de pessoas");
- gotoxy(2, 4);
- printf("Login a ser procurado: ");
- fflush(stdin);
- gets(Pes.login);
- }
- }
- fclose(PtrPes);
- getch();
- }
- int BuscaPalavraIngles(FILE *PtrPal, char Ing[40])
- {
- TpPalavra Pal;
- rewind(PtrPal);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- while(!feof(PtrPal) && stricmp(Pal.ing, Ing) != 0)
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- if(stricmp(Pal.ing, Ing) == 0)
- return ftell(PtrPal) - sizeof(TpPalavra);
- else
- return -1;
- }
- int ELetra(char c)
- {
- if(toupper(c) >= 65 && toupper(c) <= 92)
- return 1;
- else
- return 0;
- }
- void Tradutor(FILE *PtrPal)
- {
- TpPalavra Pal;
- int Pos, i, Aux;
- char Frase[1000], StrAux[1000], Traducao[1000];
- system("cls");
- Cabecalho("Tradutor");
- PtrPal = fopen("Palavra.dat", "rb");
- if(PtrPal == NULL)
- {
- gotoxy(30, 6);
- textcolor(4);
- printf("Arquivo de palavras inexistente");
- textcolor(15);
- }
- else
- {
- gotoxy(2, 4);
- printf("Texto em ingles:");
- fflush(stdin);
- gets(Frase);
- while(strcmp(Frase, "\0") != 0)
- {
- strcpy(Traducao, "\0");
- Aux = 0;
- for(i = 0; i <= strlen(Frase); i++)
- {
- if(ELetra(Frase[i]) == 1)
- StrAux[Aux++] = Frase[i];
- else if(Frase[i] == ' ' || Frase[i] == '\0')
- {
- StrAux[Aux] = '\0';
- Pos = BuscaPalavraIngles(PtrPal, StrAux);
- strcpy(StrAux, "\0");
- if(Pos == -1)
- strcat(Traducao, "? ");
- else
- {
- fseek(PtrPal, Pos, 0);
- fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
- strcat(Traducao, Pal.port);
- strcat(Traducao, " ");
- }
- Aux = 0;
- }
- }
- gotoxy(2, 5);
- printf("Traducao: %s", Traducao);
- getch();
- system("cls");
- Cabecalho("Tradutor");
- gotoxy(2, 4);
- printf("Texto em ingles:");
- fflush(stdin);
- gets(Frase);
- }
- }
- fclose(PtrPal);
- }
- void InsercaoAutomatica(FILE *PtrPes, FILE *PtrPal)
- {
- int NumRPes, NumRPal;
- TpPessoa VetPessoa = {};
- TpPalavra VetPalavra = {};
- }
- char Menu(void)
- {
- int i;
- system("cls");
- Quadro();
- textcolor(14);
- gotoxy(27, 2);
- printf("ATP 2 - JOGO DA FORCA\n");
- for(i = 2; i <= 79; i++)
- {
- gotoxy(i, 3);
- printf("%c", 205);
- }
- textbackground(4);
- gotoxy(4, 4);
- printf(" MENU DE PALAVRAS ");
- gotoxy(4, 5);
- printf("[A] - Cadastrar palavras ");
- gotoxy(4, 6);
- printf("[B] - Relatorio de palavras ");
- gotoxy(4, 7);
- printf("[C] - Alteracao de palavras ");
- gotoxy(4, 8);
- printf("[D] - Consulta de palavras ");
- gotoxy(4, 9);
- printf("[E] - Exclusao Fisica de Palavras");
- gotoxy(4, 10);
- printf("[F] - Exclusao Logica de Palavras");
- gotoxy(40, 4);
- printf(" MENU DE PESSOAS ");
- gotoxy(40, 5);
- printf("[G] - Cadastrar pessoas ");
- gotoxy(40, 6);
- printf("[H] - Relatorio de pessoas ");
- gotoxy(40, 7);
- printf("[I] - Alteracao de pessoas ");
- gotoxy(40, 8);
- printf("[J] - Consulta de pessoas ");
- gotoxy(40, 9);
- printf("[I] - Exclusao Fisica de Pessoas ");
- gotoxy(40, 10);
- printf("[K] - Exclusao Logica de Pessoas ");
- gotoxy(25, 13);
- printf(" MENU GERAL ");
- gotoxy(4, 15);
- printf("[L] - JOGAR FORCA ");
- gotoxy(40, 15);
- printf("[M] - Tradutor de frases ");
- gotoxy(4, 16);
- printf("[N] - Insercao Automatica ");
- gotoxy(40, 16);
- printf("[ESC] - Sair ");
- textbackground(0);
- textcolor(7);
- return toupper(getche());
- }
- void Executa(void)
- {
- char Op;
- FILE *PtrArq, *PtrPes;
- Op = Menu();
- while(Op != 27)
- {
- switch(Op)
- {
- case 'A':
- CadastraPalavra(PtrArq);
- break;
- case 'B':
- RelatorioPalavras(PtrArq);
- break;
- case 'C':
- AlteracaoPalavra(PtrArq);
- break;
- case 'D':
- ConsultaPalavras(PtrArq);
- break;
- case 'E':
- ExclusaoFisicaPalavra(PtrArq);
- break;
- case 'F':
- RelatorioPessoa(PtrPes);
- break;
- case 'G':
- CadastraPessoa(PtrPes);
- break;
- case 'H':
- ConsultaPessoa(PtrPes);
- break;
- case 'I':
- ExclusaoFisicaPessoa(PtrPes);
- break;
- case 'J':
- Tradutor(PtrArq);
- break;
- default:
- printf("Opcao invalida\n");
- getch();
- }
- Op = Menu();
- }
- getch();
- }
- int main(void)
- {
- Executa();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement