Advertisement
Jvsierra

atpapptaptpp

Nov 12th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 44.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "meuconio.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <time.h>
  7.  
  8. #define X_I 1
  9. #define Y_I 1
  10. #define X_F 80
  11. #define Y_F 20
  12.  
  13. struct TpPalavra
  14. {
  15.     char port[30], ing[30], significado[100];
  16.     int pont, status;  
  17. };
  18.  
  19. struct TpData
  20. {
  21.     int dia, mes, ano;
  22. };
  23.  
  24. struct TpPessoa
  25. {
  26.     char nome[40], login[10];
  27.     int senha, pont, status;
  28.     TpData Data;
  29. };
  30.  
  31. struct TpPalavForca
  32. {
  33.     char Palavra[30], Login[10];
  34.     int Acertou;
  35. };
  36.  
  37. void Quadro()
  38. {
  39.     int i;
  40.     textcolor(14);
  41.     gotoxy(X_I,Y_I);
  42.     printf("%c",201);
  43.     gotoxy(X_F,Y_I);
  44.     printf("%c",187);
  45.     gotoxy(X_I,Y_F);
  46.     printf("%c",200);
  47.     gotoxy(X_F,Y_F);
  48.     printf("%c",188);
  49.     for(i = X_I + 1; i < X_F; i++)
  50.     {
  51.         gotoxy(i, Y_I);
  52.         printf("%c", 205);
  53.         gotoxy(i, Y_F);
  54.         printf("%c", 205);
  55.     }
  56.    
  57.     for(i = Y_I + 1; i < Y_F; i++)
  58.     {
  59.         gotoxy(X_I, i);
  60.         printf("%c", 186);
  61.        
  62.         gotoxy(X_F, i);
  63.         printf("%c", 186);
  64.     }
  65.  
  66.     textcolor(15);
  67. }
  68.  
  69. void QuadroFlexivel(int XI, int YI, int XF, int YF)
  70. {
  71.     int i;
  72.     textcolor(14);
  73.     gotoxy(XI, YI);
  74.     printf("%c",201);
  75.     gotoxy(XF, YI);
  76.     printf("%c",187);
  77.     gotoxy(XI, YF);
  78.     printf("%c",200);
  79.     gotoxy(XF, YF);
  80.     printf("%c",188);
  81.    
  82.     for(i = XI + 1; i < XF; i++)
  83.     {
  84.         gotoxy(i, YI);
  85.         printf("%c", 205);
  86.         gotoxy(i, YF);
  87.         printf("%c", 205);
  88.     }
  89.    
  90.     for(i = YI + 1; i < YF; i++)
  91.     {
  92.         gotoxy(XI, i);
  93.         printf("%c", 186);
  94.        
  95.         gotoxy(XF, i);
  96.         printf("%c", 186);
  97.     }
  98. }
  99.  
  100. void Cabecalho(char Titulo[100])
  101. {
  102.     Quadro();
  103.    
  104.     textcolor(15);
  105.    
  106.     gotoxy(30, 2);
  107.    
  108.     printf("%s\n", Titulo);
  109.    
  110.     textcolor(14);
  111.    
  112.     for(int i = 2; i <= 79; i++)
  113.     {
  114.         gotoxy(i, 3);
  115.         printf("%c", 205);
  116.     }
  117.    
  118.     textcolor(15);
  119. }
  120.  
  121. void ImprimePalavra(TpPalavra Pal, int linha)
  122. {
  123.     QuadroFlexivel(2, linha - 1, 79, linha + 4);
  124.     gotoxy(3, linha++);
  125.     textcolor(14);
  126.     printf("Portugues: ");
  127.     textcolor(15);
  128.     printf("%s", Pal.port);
  129.     gotoxy(3, linha++);
  130.     textcolor(14);
  131.     printf("Ingles: ");
  132.     textcolor(15);
  133.     printf("%s", Pal.ing);
  134.     gotoxy(3, linha++);
  135.     textcolor(14);
  136.     printf("Pontuacao: ");
  137.     textcolor(15);
  138.     printf("%d", Pal.pont);
  139.     gotoxy(3, linha);
  140.     printf("%s", Pal.significado);
  141. }
  142.  
  143. void ImprimePessoa(TpPessoa Pes, int linha)
  144. {
  145.     QuadroFlexivel(2, linha - 1, 79, linha + 4);
  146.     gotoxy(3, linha++);
  147.     textcolor(14);
  148.     printf("Nome: ");
  149.     textcolor(15);
  150.     printf("%s", Pes.nome);
  151.     gotoxy(3, linha);
  152.     textcolor(14);
  153.     printf("Login: ");
  154.     textcolor(15);
  155.     printf("%s", Pes.login);
  156.     gotoxy(30, linha);
  157.     textcolor(14);
  158.     printf("Pontuacao: ");
  159.     textcolor(15);
  160.     printf("%d", Pes.pont);
  161.     linha++;
  162.     gotoxy(3, linha);
  163.     textcolor(14);
  164.     printf("Data: ");
  165.     textcolor(15);
  166.     printf("%d/%d/%d", Pes.Data.dia, Pes.Data.mes, Pes.Data.ano);
  167.    
  168.     textcolor(15); 
  169. }
  170.  
  171. void RelatorioPalavras(FILE *PtrArq)
  172. {
  173.     TpPalavra Pal;
  174.     int linha = 6;
  175.    
  176.     system("cls");
  177.    
  178.     QuadroFlexivel(1, 1, 80, 3);
  179.     gotoxy(30, 2);
  180.     printf("Relatorio de palavras");
  181.    
  182.     PtrArq = fopen("Palavra.dat", "rb");
  183.    
  184.     if(PtrArq == NULL)
  185.     {
  186.         gotoxy(30, 6);
  187.         textcolor(4);
  188.         printf("Arquivo de palavras inexistente");
  189.         textcolor(15);
  190.     }
  191.     else
  192.     {
  193.         rewind(PtrArq);
  194.        
  195.         fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  196.        
  197.         while(!feof(PtrArq))
  198.         {
  199.             if(Pal.status == 1)
  200.             {
  201.                 ImprimePalavra(Pal, linha);
  202.                 linha += 6;
  203.             }
  204.        
  205.             fread(&Pal, sizeof(TpPalavra), 1, PtrArq); 
  206.         }
  207.        
  208.         gotoxy(1, 1);
  209.     }
  210.    
  211.     fclose(PtrArq);
  212.    
  213.     getch();
  214. }
  215.  
  216. int PosicaoMaiorPessoa(FILE *PtrPes, int NumR)
  217. {
  218.     TpPessoa Pes;
  219.     int Pos, i = 0;
  220.     char MaiorNome[40];
  221.    
  222.     rewind(PtrPes);
  223.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  224.    
  225.     strcpy(MaiorNome, Pes.login);
  226.     Pos = 0;
  227.    
  228.     for(i = 1; i < NumR; i++)
  229.     {
  230.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  231.        
  232.         if(stricmp(Pes.login, MaiorNome) > 0)
  233.         {
  234.             strcpy(MaiorNome, Pes.login);
  235.             Pos = i;
  236.         }
  237.     }
  238.    
  239.     return Pos * sizeof(TpPessoa);
  240. }
  241.  
  242. void SelecaoDiretaPessoa(FILE *PtrPes)
  243. {
  244.     int PosMaior, NumR;
  245.     TpPessoa PesA, PesB;
  246.    
  247.     PtrPes = fopen("Pessoa.dat", "rb+");
  248.    
  249.     fseek(PtrPes, 0, 2);
  250.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  251.    
  252.     while(NumR > 0)
  253.     {
  254.         PosMaior = PosicaoMaiorPessoa(PtrPes, NumR);
  255.        
  256.         if(PosMaior < (NumR - 1) * sizeof(TpPessoa))
  257.         {
  258.             fseek(PtrPes, PosMaior, 0);
  259.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  260.             fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  261.             fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  262.            
  263.             fseek(PtrPes, (NumR - 1) * sizeof(TpPessoa), 0);
  264.             fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  265.             fseek(PtrPes, PosMaior, 0);
  266.             fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  267.         }
  268.        
  269.         NumR--;
  270.     }
  271.    
  272.     fclose(PtrPes);
  273. }
  274.  
  275. void InsercaoDiretaPessoa(FILE *PtrPes)
  276. {
  277.     TpPessoa PesA, PesB;
  278.     int NumR, Pos;
  279.    
  280.     fseek(PtrPes, 0, 2);
  281.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  282.    
  283.     PtrPes = fopen("Pessoa.dat", "rb+");
  284.    
  285.     clrscr();
  286.    
  287.     printf("\nNumR; %d\n", NumR);
  288.    
  289.     if(NumR > 1)
  290.     {
  291.         Pos = NumR - 1;
  292.        
  293.         fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  294.         fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  295.         fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  296.         fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  297.         printf("a: %s b:%s\n", PesA.login, PesB.login);
  298.         printf("Pos: %d\n", Pos);
  299.        
  300.         while(Pos > 0 && stricmp(PesA.login, PesB.login) < 0)
  301.         {
  302.             PtrPes = fopen("Pessoa.dat", "rb+");
  303.            
  304.             printf("a: %s b:%s\n", PesA.login, PesB.login);
  305.             printf("PosA: %d, PosB: %d\n", Pos * sizeof(TpPessoa), (Pos - 1) * sizeof(TpPessoa));
  306.             fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  307.             fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  308.             fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  309.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  310.            
  311.             Pos = Pos - 1;
  312.            
  313.             getch();
  314.            
  315.             if(Pos > 0)
  316.             {
  317.                 fseek(PtrPes, Pos * sizeof(TpPessoa), 0);
  318.                 fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  319.                 fseek(PtrPes, (Pos - 1) * sizeof(TpPessoa), 0);
  320.                 fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  321.             }
  322.            
  323.             printf("a: %s b:%s\n", PesA.login, PesB.login);
  324.             printf("PosA: %d, PosB: %d\n", Pos * sizeof(TpPessoa), (Pos - 1) * sizeof(TpPessoa));
  325.            
  326.             fclose(PtrPes);
  327.         }
  328.     }
  329.    
  330.     fclose(PtrPes);
  331.     getch();
  332. }
  333.  
  334. void RelatorioPessoa(FILE *PtrPes)
  335. {
  336.     int linha = 5;
  337.     TpPessoa Pes;
  338.    
  339.     clrscr();
  340.    
  341.     QuadroFlexivel(1, 1, 80, 3);
  342.     gotoxy(30, 2);
  343.     printf("Relatorio de pessoas");
  344.    
  345.     PtrPes = fopen("Pessoa.dat", "rb");
  346.    
  347.     if(PtrPes == NULL)
  348.     {
  349.         gotoxy(30, 6);
  350.         textcolor(4);
  351.         printf("Arquivo de pessoas inexistente");
  352.         textcolor(15);
  353.     }
  354.     else
  355.     {
  356.         rewind(PtrPes);
  357.        
  358.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  359.        
  360.         while(!feof(PtrPes))
  361.         {
  362.             if(Pes.status == 1)
  363.             {
  364.                 ImprimePessoa(Pes, linha);
  365.                 linha += 6;
  366.             }
  367.            
  368.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  369.         }
  370.        
  371.         gotoxy(1, 1);
  372.     }
  373.    
  374.     fclose(PtrPes);
  375.    
  376.     getch();
  377. }
  378.  
  379. int BuscaPalavraPort(FILE *PtrPal, char Palavra[40])
  380. {
  381.     TpPalavra Pal;
  382.    
  383.     rewind(PtrPal);
  384.    
  385.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  386.    
  387.     while(!feof(PtrPal) && stricmp(Pal.port, Palavra) != 0)
  388.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  389.    
  390.     if(stricmp(Palavra, Pal.port) == 0)
  391.         return ftell(PtrPal) - sizeof(TpPalavra);
  392.     else
  393.         return -1;
  394. }
  395.  
  396. int BuscaExaustivaPessoa(FILE *PtrPes, char login[10])
  397. {
  398.     TpPessoa Pes;
  399.    
  400.     rewind(PtrPes);
  401.    
  402.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  403.    
  404.     while(!feof(PtrPes) && (stricmp(login, Pes.login) != 0 || Pes.status == 0))
  405.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  406.        
  407.     if(stricmp(login, Pes.login) == 0)
  408.         return ftell(PtrPes) - sizeof(TpPessoa);
  409.     else
  410.         return -1;
  411. }
  412. void BubbleSortPessoa(FILE *PtrPes)
  413. {
  414.     TpPessoa PesA, PesB;
  415.     int i, j, QntdR;
  416.    
  417.     PtrPes = fopen("Pessoa.dat", "rb+");
  418.    
  419.     fseek(PtrPes, 0, 2);
  420.        
  421.     QntdR = ftell(PtrPes) / sizeof(TpPessoa);
  422.        
  423.     while(QntdR > 0)
  424.     {
  425.         for(i = 0; i < QntdR - 1; i++)
  426.         {
  427.             fseek(PtrPes, i * sizeof(TpPessoa), 0);
  428.             fread(&PesA, sizeof(TpPessoa), 1, PtrPes);
  429.             fread(&PesB, sizeof(TpPessoa), 1, PtrPes);
  430.                
  431.             if(stricmp(PesA.nome, PesB.nome) > 0)
  432.             {
  433.                 fseek(PtrPes, i * sizeof(TpPessoa), 0);
  434.                 fwrite(&PesB, sizeof(TpPessoa), 1, PtrPes);
  435.                 fwrite(&PesA, sizeof(TpPessoa), 1, PtrPes);
  436.             }
  437.         }
  438.            
  439.             QntdR--;
  440.     }
  441.    
  442.     fclose(PtrPes);
  443.    
  444.     getch();
  445. }
  446.  
  447. void BubbleSortPalavra(FILE *PtrPal)
  448. {
  449.     TpPalavra PalA, PalB;
  450.     int i, j, QntdR;
  451.    
  452.     PtrPal = fopen("Palavra.dat", "rb+");
  453.    
  454.     fseek(PtrPal, 0, 2);
  455.     QntdR = ftell(PtrPal) / sizeof(TpPalavra);
  456.    
  457.     while(QntdR > 0)
  458.     {
  459.         for(i = 0; i < QntdR - 1; i++)
  460.         {
  461.             fseek(PtrPal, i * sizeof(TpPalavra), 0);
  462.             fread(&PalA, sizeof(TpPalavra), 1, PtrPal);
  463.             fread(&PalB, sizeof(TpPalavra), 1, PtrPal);
  464.                
  465.             if(stricmp(PalA.port, PalB.port) > 0)
  466.             {
  467.                 fseek(PtrPal, i * sizeof(TpPalavra), 0);
  468.                 fwrite(&PalB, sizeof(TpPalavra), 1, PtrPal);
  469.                 fwrite(&PalA, sizeof(TpPalavra), 1, PtrPal);
  470.             }
  471.         }
  472.        
  473.         QntdR--;
  474.     }
  475.    
  476.     fclose(PtrPal);
  477. }
  478.  
  479. int BuscaSeqIndPessoa(FILE *PtrPes, char loginChave[10])
  480. {
  481.     TpPessoa Pes;
  482.  
  483.     rewind(PtrPes);
  484.    
  485.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  486.    
  487.     while(!feof(PtrPes) && (stricmp(loginChave, Pes.login) > 0 || Pes.login == 0))
  488.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  489.        
  490.     if(stricmp(loginChave, Pes.login) == 0)
  491.         return ftell(PtrPes) - sizeof(TpPessoa);
  492.     else
  493.         return -1;
  494. }
  495.  
  496. int BuscaSentinelaPessoa(FILE *PtrPes, char loginChave[10])
  497. {
  498.     FILE *PtrAux;
  499.     int i, j, NumR;
  500.     TpPessoa Pes;
  501.     //Implementado, funcionando, não usei devido ao custo computacional
  502.    
  503.     PtrPes = fopen("Palavra.dat", "rb+");
  504.    
  505.     strcpy(Pes.login, loginChave);
  506.     Pes.status = 1;
  507.    
  508.     fseek(PtrPes, 0, 2);
  509.    
  510.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  511.    
  512.     fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  513.    
  514.     rewind(PtrPes);
  515.    
  516.     i = 0;
  517.    
  518.     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  519.    
  520.     while(i < NumR && (strcmp(Pes.login, loginChave) != 0 || Pes.status == 0))
  521.     {
  522.         printf("%s - %s\n", Pes.login, loginChave);
  523.         printf("%d \n", Pes.status);
  524.         i++;
  525.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  526.     }
  527.    
  528.     rewind(PtrPes);
  529.    
  530.     PtrAux = fopen("Temp.dat", "ab+");
  531.    
  532.     for(j = 0; j < NumR; j++)
  533.     {
  534.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  535.        
  536.         fwrite(&Pes, sizeof(TpPessoa), 1, PtrAux);
  537.     }
  538.    
  539.     fclose(PtrPes);
  540.     fclose(PtrAux);
  541.    
  542.     remove("Pessoa.dat");  
  543.     rename("Temp.dat", "Pessoa.dat");
  544.  
  545.     printf("i: %d, tl: %d", i, NumR);
  546.  
  547.     if(i < NumR)
  548.         return i * sizeof(TpPessoa);
  549.     else
  550.         return -1;
  551. }
  552.  
  553. int BuscaBinariaPessoa(FILE *PtrPes, char loginChave[10])
  554. {
  555.     int inicio = 0, meio, fim;
  556.     TpPessoa R;
  557.    
  558.     fseek(PtrPes, 0, 2);
  559.    
  560.     fim = ftell(PtrPes) / sizeof(TpPessoa) - 1;
  561.    
  562.     meio = fim / 2;
  563.    
  564.     fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  565.     fread(&R, sizeof(TpPessoa), 1, PtrPes);
  566.    
  567.     while(inicio < fim && (strcmp(loginChave, R.login) != 0 || R.status == 0))
  568.     {
  569.         if(strcmp(loginChave, R.login) > 0)
  570.             inicio = meio + 1;
  571.         else
  572.             fim = meio - 1;
  573.            
  574.         meio = (inicio + fim) / 2;
  575.        
  576.         fseek(PtrPes, meio * sizeof(TpPessoa), 0);
  577.         fread(&R, sizeof(TpPessoa), 1, PtrPes);
  578.     }
  579.    
  580.     if(strcmp(loginChave, R.login) == 0)
  581.         return meio * sizeof(TpPessoa);
  582.     else
  583.         return -1;
  584. }
  585.  
  586. void ExclusaoFisicaPessoa(FILE *PtrPes)
  587. {
  588.     TpPessoa Pes;
  589.     char LoginAux[10];
  590.     int Pos;
  591.    
  592.     system("cls");
  593.     Cabecalho("Exclusao Fisica de Pessoas");
  594.    
  595.     gotoxy(2, 4);
  596.     printf("Pessoa a ser excluida:");
  597.     fflush(stdin);
  598.     gets(LoginAux);
  599.    
  600.     while(strcmp(LoginAux, "\0") != 0)
  601.     {
  602.         PtrPes = fopen("Pessoa.dat", "rb");
  603.        
  604.         if(PtrPes == NULL)
  605.         {
  606.             gotoxy(30, 6);
  607.             textcolor(4);
  608.             printf("Arquivo de pessoas inexistente");
  609.             textcolor(15);
  610.             fclose(PtrPes);
  611.         }
  612.         else
  613.         {
  614.             Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
  615.                
  616.             if(Pos == -1)
  617.             {
  618.                 gotoxy(30, 6);
  619.                 textcolor(4);
  620.                 printf("Login nao cadastrado");
  621.                 textcolor(15);
  622.                 fclose(PtrPes);
  623.             }
  624.             else
  625.             {
  626.                 gotoxy(2, 5);
  627.                 printf("Dados encontrados:");      
  628.                 fseek(PtrPes, Pos, 0);
  629.                 fread(&Pes, sizeof(TpPessoa), 1, PtrPes);  
  630.                 ImprimePessoa(Pes, 7);
  631.                            
  632.                 gotoxy(2, 12);
  633.                 printf("Confirma exclusao?(S/N)");
  634.                            
  635.                 if(toupper(getche()) == 'S')
  636.                 {
  637.                     FILE *PtrTemp = fopen("Temp.dat", "ab+");
  638.                            
  639.                     rewind(PtrPes);
  640.                                
  641.                     fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  642.                            
  643.                     while(!feof(PtrPes))
  644.                     {
  645.                         if(strcmp(Pes.login, LoginAux) != 0)
  646.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrTemp);
  647.                                        
  648.                         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  649.                     }
  650.                                
  651.                     fclose(PtrPes);
  652.                     fclose(PtrTemp);
  653.                                
  654.                     remove("Pessoa.dat");
  655.                     rename("Temp.dat", "Pessoa.dat");
  656.                                
  657.                     textcolor(3);
  658.                     gotoxy(25, 15);
  659.                     printf("Pessoa excluida!");
  660.                 }
  661.                 else
  662.                     fclose(PtrPes);
  663.             }
  664.            
  665.             getch();
  666.            
  667.             system("cls");
  668.             Cabecalho("Exclusao Fisica de Pessoas");
  669.                
  670.             gotoxy(2, 4);
  671.             printf("Pessoa a ser excluida:");
  672.             fflush(stdin);
  673.             gets(LoginAux);
  674.         }
  675.     }  
  676.    
  677.     getch();
  678. }
  679.  
  680. void ExclusaoLogicaPessoa(FILE *PtrPes)
  681. {
  682.     TpPessoa Pes;
  683.     int Pos;
  684.     char LoginAux[10];
  685.    
  686.     system("cls");
  687.     Cabecalho("Exclusao Logica de Pessoas");
  688.    
  689.     PtrPes = fopen("Pessoa.dat", "rb+");
  690.  
  691.     gotoxy(2, 4);
  692.     printf("Login:");
  693.     fflush(stdin);
  694.     gets(LoginAux);
  695.        
  696.     while(strcmp(LoginAux, "\0") != 0)
  697.     {
  698.         Pos = BuscaBinariaPessoa(PtrPes, LoginAux);
  699.            
  700.         if(Pos == -1)
  701.         {
  702.             gotoxy(30, 6);
  703.             textcolor(4);
  704.             printf("Login nao cadastrado");
  705.             textcolor(15);
  706.             fclose(PtrPes);
  707.         }
  708.         else
  709.         {
  710.             gotoxy(2, 5);
  711.             printf("Dados encontrados:");      
  712.             fseek(PtrPes, Pos, 0);
  713.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);  
  714.             ImprimePessoa(Pes, 7);
  715.                            
  716.             gotoxy(2, 12);
  717.             printf("Confirma exclusao?(S/N)");
  718.            
  719.             if(toupper(getche()) == 'S')
  720.             {
  721.                 Pes.status = 0;
  722.                 fseek(PtrPes, Pos, 0);
  723.                 fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  724.                
  725.                 textcolor(3);
  726.                 gotoxy(25, 15);
  727.                 printf("Pessoa excluida!");
  728.             }
  729.         }
  730.        
  731.         getch();
  732.        
  733.         system("cls");
  734.         Cabecalho("Exclusao Logica de Pessoas");
  735.            
  736.         gotoxy(2, 4);
  737.         printf("Login:");
  738.         fflush(stdin);
  739.         gets(LoginAux);
  740.     }
  741.    
  742.     fclose(PtrPes);
  743.    
  744.     getch();
  745. }
  746.  
  747. void ConsultaPalavras(FILE *PtrArq)
  748. {
  749.     TpPalavra Pal;
  750.     int Pos, linha;
  751.    
  752.     system("cls");
  753.     Cabecalho("Consulta de Palavras");
  754.    
  755.     PtrArq = fopen("Palavra.dat", "rb");
  756.    
  757.     if(PtrArq == NULL)
  758.     {
  759.         gotoxy(30, 6);
  760.         textcolor(4);
  761.         printf("Arquivo de palavras inexistente");
  762.         textcolor(15);
  763.     }
  764.     else
  765.     {
  766.         gotoxy(2, 4);
  767.         printf("Palavra em portugues:");
  768.         fflush(stdin);
  769.         gets(Pal.port);
  770.        
  771.         while(strcmp(Pal.port, "\0") != 0)
  772.         {
  773.             Pos = BuscaPalavraPort(PtrArq, Pal.port);
  774.            
  775.             if(Pos == -1)
  776.             {
  777.                 gotoxy(30, 6);
  778.                 textcolor(4);
  779.                 printf("Palavra inexistente");
  780.                 textcolor(15);
  781.             }
  782.             else
  783.             {
  784.                 gotoxy(30, 5);
  785.                 printf("Dados encontrados:");
  786.                 fseek(PtrArq, Pos, 0);
  787.                 fread(&Pal, sizeof(TpPalavra), 1, PtrArq);
  788.                
  789.                 ImprimePalavra(Pal, 7);
  790.             }
  791.            
  792.             getch();
  793.            
  794.             system("cls");
  795.             Cabecalho("Consulta de Palavras");
  796.            
  797.             gotoxy(2, 4);
  798.             printf("Palavra em portugues:");
  799.             fflush(stdin);
  800.             gets(Pal.port);
  801.         }
  802.     }
  803.    
  804.     fclose(PtrArq);
  805.    
  806.     getch();
  807. }
  808.  
  809. char MenuAlteraPessoa(void)
  810. {
  811.     gotoxy(3, 6);
  812.     printf("[A] - Alterar nome");
  813.     gotoxy(3, 7);
  814.     printf("[B] - Alterar senha");
  815.     gotoxy(3, 8);
  816.     printf("[ESC] - Sair    ");
  817.    
  818.     return toupper(getche());
  819. }
  820.  
  821. char MenuAlteraPalavra(void)
  822. {
  823.     gotoxy(3, 6);
  824.     printf("[A] - Alterar palavra em ingles");
  825.     gotoxy(3, 7);
  826.     printf("[B] - Alterar pontuacao");
  827.     gotoxy(3, 8);
  828.     printf("[C] - Alterar significado ");
  829.     gotoxy(3, 9);
  830.     printf("[ESC] - Sair    ");
  831.    
  832.     return toupper(getche());
  833. }
  834.  
  835. void CadastraPalavra(FILE *PtrPal)
  836. {
  837.     TpPalavra Pal;
  838.    
  839.     system("cls");
  840.     Cabecalho("Cadastro de Palavras");
  841.    
  842.     PtrPal = fopen("Palavra.dat", "ab+");
  843.    
  844.     gotoxy(2, 4);
  845.     printf("Palavra em portugues: ");
  846.     fflush(stdin);
  847.     gets(Pal.port);
  848.    
  849.     while(strcmp(Pal.port, "\0") != 0)
  850.     {
  851.         if(BuscaPalavraPort(PtrPal, Pal.port) >= 0)
  852.         {
  853.             gotoxy(30, 6);
  854.             textcolor(4);
  855.             printf("Palavra ja cadastrada");
  856.             textcolor(15);
  857.         }
  858.         else
  859.         {
  860.             gotoxy(2, 5);
  861.             printf("Palavra em ingles: ");
  862.             fflush(stdin);
  863.             gets(Pal.ing);
  864.            
  865.             while(strcmp(Pal.ing, "\0") == 0)
  866.             {
  867.                 textcolor(4);
  868.                 gotoxy(2, 6);
  869.                 printf("Digite uma palavra valida:");
  870.                 fflush(stdin);
  871.                 textcolor(15);
  872.                 gets(Pal.ing);
  873.             }
  874.            
  875.             gotoxy(2, 7);
  876.             printf("Significado da palavra: ");
  877.             fflush(stdin);
  878.             gets(Pal.significado);
  879.            
  880.             while(strcmp(Pal.significado, "\0") == 0)
  881.             {
  882.                 textcolor(4);
  883.                 gotoxy(2, 8);
  884.                 printf("Digite um significado valido:");
  885.                 fflush(stdin);
  886.                 textcolor(15);
  887.                 gets(Pal.significado);
  888.             }  
  889.            
  890.             gotoxy(2, 9);
  891.             printf("Pontuacao: ");
  892.             scanf("%d", &Pal.pont);
  893.            
  894.             while(Pal.pont <= 0)
  895.             {
  896.                 textcolor(4);
  897.                 gotoxy(2, 10);
  898.                 printf("Digite uma pontuacao valida:");
  899.                 textcolor(15);
  900.                 scanf("%d", &Pal.pont);
  901.             }
  902.            
  903.             Pal.status = 1;
  904.            
  905.             fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  906.            
  907.             textcolor(3);
  908.             gotoxy(25, 15);
  909.             printf("Palavra cadastrada!");
  910.         }
  911.        
  912.         getch();
  913.        
  914.         system("cls");
  915.         Cabecalho("Cadastro de Palavras");
  916.         gotoxy(2, 4);
  917.         printf("Palavra em portugues: ");
  918.         fflush(stdin);
  919.         gets(Pal.port);
  920.     }
  921.    
  922.     getch();
  923.    
  924.     fclose(PtrPal);
  925. }
  926.  
  927. void AlteracaoPalavra(FILE *PtrPal)
  928. {
  929.     TpPalavra Pal;
  930.     char Op;
  931.     int Pos;
  932.    
  933.     system("cls");
  934.    
  935.     Cabecalho("Alteracao de Palavras");
  936.    
  937.     PtrPal = fopen("Palavra.dat", "rb+");
  938.    
  939.     gotoxy(2, 4);
  940.     printf("Palavra em portugues: ");
  941.     fflush(stdin);
  942.     gets(Pal.port);
  943.    
  944.     while(strcmp(Pal.port, "\0") != 0)
  945.     {
  946.         Pos = BuscaPalavraPort(PtrPal, Pal.port);
  947.        
  948.         if(Pos == -1)
  949.         {
  950.             gotoxy(30, 6);
  951.             textcolor(4);
  952.             printf("Palavra inexistente");
  953.             textcolor(15);
  954.         }
  955.         else
  956.         {
  957.             fseek(PtrPal, Pos, 0);
  958.            
  959.             fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  960.            
  961.             Op = MenuAlteraPalavra();
  962.            
  963.             while(Op != 27)
  964.             {
  965.                 switch(Op)
  966.                 {
  967.                     case 'A':
  968.                         gotoxy(2, 10);
  969.                         printf("Palavra em ingles atual: %s", Pal.ing);
  970.                        
  971.                         gotoxy(2, 11);
  972.                         printf("Nova palavra em ingles: ");
  973.                         fflush(stdin);
  974.                         gets(Pal.ing);
  975.                        
  976.                         while(strcmp(Pal.ing, "\0") == 0)
  977.                         {
  978.                             textcolor(4);
  979.                             gotoxy(2, 12);
  980.                             printf("Digite uma palavra valida:");
  981.                             fflush(stdin);
  982.                             textcolor(15);
  983.                             gets(Pal.ing);
  984.                         }
  985.                        
  986.                         fseek(PtrPal, Pos, 0);
  987.                         fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  988.                        
  989.                         textcolor(3);
  990.                         gotoxy(25, 15);
  991.                         printf("Palavra alterada!");
  992.                     break;
  993.                     case 'B':
  994.                         gotoxy(2, 10);
  995.                         printf("Pontuacao atual: %d", Pal.pont);
  996.                            
  997.                         gotoxy(2, 11);
  998.                         printf("Nova pontuacao: ");
  999.                         scanf("%d", &Pal.pont);
  1000.                        
  1001.                         while(Pal.pont <= 0)
  1002.                         {
  1003.                             textcolor(4);
  1004.                             gotoxy(2, 12);
  1005.                             printf("Digite uma pontuacao valida:");
  1006.                             textcolor(15);
  1007.                             scanf("%d", &Pal.pont);
  1008.                         }
  1009.                            
  1010.                         textcolor(3);
  1011.                         gotoxy(25, 15);
  1012.                         printf("Pontuacao alterada!");
  1013.                     break;
  1014.                     case 'C':
  1015.                         gotoxy(2, 10);
  1016.                         printf("Significado atual: %s", Pal.significado);
  1017.                        
  1018.                         gotoxy(2, 11);
  1019.                         printf("Novo significado: ");
  1020.                         fflush(stdin);
  1021.                         gets(Pal.significado);
  1022.                        
  1023.                         while(strcmp(Pal.significado, "\0") == 0)
  1024.                         {
  1025.                             textcolor(4);
  1026.                             gotoxy(2, 12);
  1027.                             printf("Digite um significado valido:");
  1028.                             fflush(stdin);
  1029.                             textcolor(15);
  1030.                             gets(Pal.significado);
  1031.                         }
  1032.                        
  1033.                         fseek(PtrPal, Pos, 0);
  1034.                         fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1035.                        
  1036.                         textcolor(3);
  1037.                         gotoxy(25, 15);
  1038.                         printf("Significado alterado!");   
  1039.                     break;
  1040.                     default:
  1041.                         gotoxy(2, 11);
  1042.                         textcolor(4);
  1043.                         printf("Opcao invalida!");
  1044.                         textcolor(15);
  1045.                     break;
  1046.                 }
  1047.                
  1048.                 getch();
  1049.                 system("cls");
  1050.                 Cabecalho("Alteracao de Palavras");
  1051.                
  1052.                 Op = MenuAlteraPalavra();
  1053.             }
  1054.         }
  1055.        
  1056.         getch();
  1057.        
  1058.         system("cls");
  1059.         Cabecalho("Alteracao de Palavras");
  1060.        
  1061.         gotoxy(2, 4);
  1062.         printf("Palavra em portugues: ");
  1063.         gotoxy(2, 5);
  1064.         fflush(stdin);
  1065.         gets(Pal.port);
  1066.     }
  1067.    
  1068.     fclose(PtrPal);
  1069.    
  1070.     getch();
  1071. }
  1072.  
  1073. void ExclusaoFisicaPalavra(FILE *PtrPal)
  1074. {
  1075.     TpPalavra Pal;
  1076.     int Pos;
  1077.     char PalavraAux[40];
  1078.    
  1079.     system("cls");
  1080.     Cabecalho("Exclusao Fisica de Palavras");
  1081.    
  1082.     gotoxy(2, 4);
  1083.     printf("Palavra a ser excluida:");
  1084.     fflush(stdin);
  1085.     gets(PalavraAux);
  1086.    
  1087.     while(strcmp(PalavraAux, "\0") != 0)
  1088.     {
  1089.         PtrPal = fopen("Palavra.dat", "rb");
  1090.        
  1091.         if(PtrPal == NULL)
  1092.         {
  1093.             gotoxy(30, 6);
  1094.             textcolor(4);
  1095.             printf("Arquivo de palavras inexistente");
  1096.             textcolor(15);
  1097.             fclose(PtrPal);
  1098.         }
  1099.         else
  1100.         {
  1101.             Pos = BuscaPalavraPort(PtrPal, PalavraAux);
  1102.            
  1103.             if(Pos == -1)
  1104.             {
  1105.                 gotoxy(30, 6);
  1106.                 textcolor(4);
  1107.                 printf("Palavra inexistente");
  1108.                 textcolor(15);
  1109.                 fclose(PtrPal);
  1110.             }
  1111.             else
  1112.             {
  1113.                 fseek(PtrPal, Pos, 0);
  1114.                 fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1115.                 gotoxy(2, 5);
  1116.                 printf("Dados encontrados:");
  1117.                 ImprimePalavra(Pal, 7);
  1118.                
  1119.                 gotoxy(2, 12);
  1120.                 printf("Confirma exclusao?(S/N)");
  1121.                
  1122.                 if(toupper(getche()) == 'S')
  1123.                 {
  1124.                     FILE *PtrTemp = fopen("Temp.dat", "ab+");
  1125.                    
  1126.                     rewind(PtrPal);
  1127.                    
  1128.                     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1129.                    
  1130.                     while(!feof(PtrPal))
  1131.                     {
  1132.                         if(strcmp(Pal.port, PalavraAux) != 0)
  1133.                             fwrite(&Pal, sizeof(TpPalavra), 1, PtrTemp);
  1134.                            
  1135.                         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1136.                     }
  1137.                    
  1138.                     fclose(PtrPal);
  1139.                     fclose(PtrTemp);
  1140.                    
  1141.                     remove("Palavra.dat");
  1142.                     rename("Temp.dat", "Palavra.dat");
  1143.                    
  1144.                     textcolor(3);
  1145.                     gotoxy(25, 15);
  1146.                     printf("Palavra excluida!");
  1147.                 }
  1148.                 else
  1149.                     fclose(PtrPal);
  1150.             }
  1151.         }
  1152.        
  1153.         getch();
  1154.        
  1155.         system("cls");
  1156.         Cabecalho("Exclusao Fisica de Palavras");
  1157.         gotoxy(2, 4);
  1158.         printf("Palavra a ser excluida:");
  1159.         fflush(stdin);
  1160.         gets(PalavraAux);
  1161.     }
  1162.    
  1163.     getch();
  1164. }
  1165.  
  1166. void ExclusaoLogicaPalavra(FILE *PtrPal)
  1167. {
  1168.     TpPalavra Pal;
  1169.     int Pos;
  1170.    
  1171.     system("cls");
  1172.     Cabecalho("Exclusao Logica de Palavras");
  1173.    
  1174.     PtrPal = fopen("Palavra.dat", "rb+");
  1175.    
  1176.     gotoxy(2, 4);
  1177.     printf("Palavra a ser excluida:");
  1178.     fflush(stdin);
  1179.     gets(Pal.port);
  1180.    
  1181.     while(strcmp(Pal.port, "\0") != 0)
  1182.     {
  1183.         Pos = BuscaPalavraPort(PtrPal, Pal.port);
  1184.        
  1185.         if(Pos == -1)
  1186.         {
  1187.             gotoxy(30, 6);
  1188.             textcolor(4);
  1189.             printf("Palavra inexistente");
  1190.             textcolor(15);
  1191.             fclose(PtrPal);
  1192.         }
  1193.         else
  1194.         {
  1195.             fseek(PtrPal, Pos, 0);
  1196.             fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1197.             gotoxy(2, 5);
  1198.             printf("Dados encontrados:");
  1199.             ImprimePalavra(Pal, 7);
  1200.                
  1201.             gotoxy(2, 12);
  1202.             printf("Confirma exclusao?(S/N)");
  1203.        
  1204.             if(toupper(getche()) == 'S')
  1205.             {
  1206.                 Pal.status = 0;
  1207.                
  1208.                 fseek(PtrPal, Pos, 0);
  1209.                 fwrite(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1210.            
  1211.                 textcolor(3);
  1212.                 gotoxy(25, 15);
  1213.                 printf("Palavra excluida!");
  1214.             }
  1215.         }
  1216.        
  1217.         getch();
  1218.        
  1219.         system("cls");
  1220.         Cabecalho("Exclusao Logica de Palavras");
  1221.        
  1222.         gotoxy(2, 4);
  1223.         printf("Palavra a ser excluida:");
  1224.         fflush(stdin);
  1225.         gets(Pal.port);
  1226.     }
  1227.    
  1228.     fclose(PtrPal);
  1229.    
  1230.     getch();
  1231. }
  1232.  
  1233. void CadastraPessoa(FILE *PtrPes)
  1234. {
  1235.     TpPessoa Pes;
  1236.    
  1237.     time_t t = time(NULL);
  1238.     struct tm tm = *localtime(&t);
  1239.    
  1240.     system("cls");
  1241.     Cabecalho("Cadastro de Pessoas");
  1242.    
  1243.     PtrPes = fopen("Pessoa.dat", "ab+");
  1244.    
  1245.     gotoxy(2, 4);
  1246.     printf("Login a ser cadastrado: ");
  1247.     fflush(stdin);
  1248.     gets(Pes.login);
  1249.    
  1250.     while(strcmp(Pes.login, "\0") != 0)
  1251.     {
  1252.         if(BuscaExaustivaPessoa(PtrPes, Pes.login) >= 0)
  1253.         {
  1254.             gotoxy(30, 6);
  1255.             textcolor(4);
  1256.             printf("Login ja cadastrado");
  1257.             textcolor(15);
  1258.         }
  1259.         else
  1260.         {
  1261.             gotoxy(2, 5);
  1262.             printf("Nome: ");
  1263.             fflush(stdin);
  1264.             gets(Pes.nome);
  1265.            
  1266.             while(strcmp(Pes.nome, "\0") == 0)
  1267.             {
  1268.                 textcolor(4);
  1269.                 gotoxy(2, 6);
  1270.                 printf("Digite um nome valido:");
  1271.                 fflush(stdin);
  1272.                 textcolor(15);
  1273.                 gets(Pes.nome);
  1274.             }
  1275.            
  1276.             gotoxy(2, 7);
  1277.             printf("Senha: "); textcolor(0);
  1278.             scanf("%d", &Pes.senha);
  1279.                        
  1280.             while(Pes.senha <= 0)
  1281.             {
  1282.                 textcolor(4);
  1283.                 gotoxy(2, 8);
  1284.                 printf("Digite uma senha valida:");
  1285.                 textcolor(0);
  1286.                 scanf("%d", &Pes.senha);
  1287.             }
  1288.            
  1289.             textcolor(15);
  1290.    
  1291.             Pes.Data.dia = tm.tm_mday;
  1292.             Pes.Data.mes = tm.tm_mon + 1;
  1293.             Pes.Data.ano = tm.tm_year + 1900;
  1294.                
  1295.             Pes.pont = 0;
  1296.             Pes.status = 1;    
  1297.             fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1298.            
  1299.             textcolor(3);
  1300.             gotoxy(25, 15);
  1301.             printf("Pessoa cadastrada!");
  1302.         }
  1303.        
  1304.         getch();
  1305.        
  1306.         system("cls");
  1307.         Cabecalho("Cadastro de Pessoas");
  1308.        
  1309.         gotoxy(2, 4);
  1310.         printf("Login a ser cadastrado: ");
  1311.         fflush(stdin);
  1312.         gets(Pes.login);
  1313.     }
  1314.    
  1315.     fclose(PtrPes);
  1316.     InsercaoDiretaPessoa(PtrPes);
  1317.    
  1318.     getch();
  1319. }
  1320.  
  1321. void AlteracaoPessoa(FILE *PtrPes)
  1322. {
  1323.     TpPessoa Pes;
  1324.     int Pos;
  1325.     char Op;
  1326.    
  1327.     system("cls");
  1328.     Cabecalho("Alteracao de Pessoas");
  1329.    
  1330.     PtrPes = fopen("Pessoa.dat", "rb+");
  1331.    
  1332.     gotoxy(2, 4);
  1333.     printf("Login da pessoa a ser alterada: ");
  1334.     fflush(stdin);
  1335.     gets(Pes.login);
  1336.    
  1337.     while(strcmp(Pes.login, "\0") != 0)
  1338.     {
  1339.         Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
  1340.        
  1341.         if(Pos == -1)
  1342.         {
  1343.             gotoxy(30, 6);
  1344.             textcolor(4);
  1345.             printf("Login inexistente!");  
  1346.             textcolor(15);
  1347.         }
  1348.         else
  1349.         {
  1350.             fseek(PtrPes, Pos, 0);
  1351.            
  1352.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1353.            
  1354.             Op = MenuAlteraPessoa();
  1355.            
  1356.             while(Op != 27)
  1357.             {
  1358.                 switch(Op)
  1359.                 {
  1360.                     case 'A':
  1361.                         gotoxy(2, 10);
  1362.                         printf("Nome atual: %s\n", Pes.nome);
  1363.                         gotoxy(2, 11);
  1364.                         printf("Novo nome: ");
  1365.                         fflush(stdin);
  1366.                         gets(Pes.nome);
  1367.                        
  1368.                         while(strcmp(Pes.nome, "\0") == 0)
  1369.                         {
  1370.                             textcolor(4);
  1371.                             gotoxy(2, 12);
  1372.                             printf("Digite um nome valido:");
  1373.                             fflush(stdin);
  1374.                             textcolor(15);
  1375.                             gets(Pes.nome);
  1376.                         }
  1377.                        
  1378.                         fseek(PtrPes, Pos, 0);
  1379.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1380.                        
  1381.                         textcolor(3);
  1382.                         gotoxy(25, 15);
  1383.                         printf("Nome alterado!");
  1384.                     break;
  1385.                     case 'B':
  1386.                         gotoxy(2, 10);
  1387.                         printf("Senha atual: %d\n", Pes.senha);
  1388.                         gotoxy(2, 11);
  1389.                         printf("Nova senha: "); textcolor(0);
  1390.                         scanf("%d", &Pes.senha);
  1391.                        
  1392.                         while(Pes.senha <= 0)
  1393.                         {
  1394.                             textcolor(4);
  1395.                             gotoxy(2, 12);
  1396.                             printf("Digite uma senha valida:");
  1397.                             textcolor(0);
  1398.                             scanf("%d", &Pes.senha);
  1399.                         }
  1400.                        
  1401.                         fseek(PtrPes, Pos, 0);
  1402.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1403.                        
  1404.                         textcolor(3);
  1405.                         gotoxy(25, 15);
  1406.                         printf("Senha alterada!");
  1407.                     break;
  1408.                     default:
  1409.                         gotoxy(2, 11);
  1410.                         textcolor(4);
  1411.                         printf("Opcao invalida!");
  1412.                         textcolor(15);
  1413.                     break;
  1414.                 }
  1415.                
  1416.                 getch();
  1417.                 system("cls");
  1418.                 Cabecalho("Alteracao de Pessoas");
  1419.                
  1420.                 Op = MenuAlteraPessoa();
  1421.             }
  1422.         }
  1423.        
  1424.         getch();
  1425.        
  1426.         system("cls");
  1427.         Cabecalho("Alteracao de Pessoas");
  1428.        
  1429.         gotoxy(2, 4);
  1430.         printf("Login da pessoa a ser alterada: ");
  1431.         fflush(stdin);
  1432.         gets(Pes.login);
  1433.     }
  1434.    
  1435.     fclose(PtrPes);
  1436.    
  1437.     getch();
  1438. }
  1439.  
  1440. int BuscaBinariaPalavra(FILE *PtrPal, char palavraChave[40])
  1441. {
  1442.     TpPalavra Pal;
  1443.     int inicio = 0, meio, fim;
  1444.    
  1445.     fseek(PtrPal, 0, 2);
  1446.    
  1447.     fim = ftell(PtrPal) / sizeof(TpPalavra) - 1;
  1448.    
  1449.     meio = fim / 2;
  1450.    
  1451.     fseek(PtrPal, meio, 0);
  1452.    
  1453.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1454.    
  1455.     while(inicio < fim && (stricmp(palavraChave, Pal.port) != 0 || Pal.status == 0))
  1456.     {
  1457.         if(stricmp(palavraChave, Pal.port) > 0)
  1458.             inicio = meio + 1;
  1459.         else
  1460.             inicio = meio - 1;
  1461.            
  1462.         meio = (inicio + fim) / 2;
  1463.        
  1464.         fseek(PtrPal, meio, 0);
  1465.        
  1466.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1467.     }
  1468.    
  1469.     if(stricmp(palavraChave, Pal.port) == 0)
  1470.         return meio * sizeof(TpPalavra);
  1471.     else
  1472.         return -1;
  1473. }
  1474.  
  1475. void ConsultaPessoa(FILE *PtrPes)
  1476. {
  1477.     TpPessoa Pes;
  1478.     int Pos;
  1479.    
  1480.     system("cls");
  1481.     Cabecalho("Consulta de pessoas");
  1482.    
  1483.     PtrPes = fopen("Pessoa.dat", "rb");
  1484.    
  1485.     if(PtrPes == NULL)
  1486.     {
  1487.         gotoxy(30, 6);
  1488.         textcolor(4);
  1489.         printf("Arquivo de pessoas inexistente");
  1490.         textcolor(15);
  1491.     }
  1492.     else
  1493.     {
  1494.         gotoxy(2, 4);
  1495.         printf("Login a ser procurado: ");
  1496.         fflush(stdin);
  1497.         gets(Pes.login);
  1498.        
  1499.         while(strcmp(Pes.login, "\0") != 0)
  1500.         {
  1501.             Pos = BuscaBinariaPessoa(PtrPes, Pes.login);
  1502.            
  1503.             if(Pos == -1)
  1504.             {
  1505.                 gotoxy(30, 6);
  1506.                 textcolor(4);
  1507.                 printf("Login inexistente");
  1508.                 textcolor(15);
  1509.             }
  1510.             else
  1511.             {
  1512.                 gotoxy(30, 5);
  1513.                 printf("Dados encontrados:");
  1514.                 fseek(PtrPes, Pos, 0);
  1515.                 fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1516.                 ImprimePessoa(Pes, 7);
  1517.             }
  1518.            
  1519.             getch();
  1520.            
  1521.             system("cls");
  1522.             Cabecalho("Consulta de pessoas");
  1523.                    
  1524.             gotoxy(2, 4);
  1525.             printf("Login a ser procurado: ");
  1526.             fflush(stdin);
  1527.             gets(Pes.login);
  1528.         }
  1529.     }
  1530.    
  1531.     fclose(PtrPes);
  1532.     getch();
  1533. }
  1534.  
  1535. int BuscaPalavraIngles(FILE *PtrPal, char Ing[40])
  1536. {
  1537.     TpPalavra Pal;
  1538.    
  1539.     rewind(PtrPal);
  1540.    
  1541.     fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1542.    
  1543.     while(!feof(PtrPal) && (stricmp(Pal.ing, Ing) != 0 || Pal.status == 0))
  1544.         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1545.        
  1546.     if(stricmp(Pal.ing, Ing) == 0)
  1547.         return ftell(PtrPal) - sizeof(TpPalavra);
  1548.     else
  1549.         return -1;
  1550. }
  1551.  
  1552. int ELetra(char c)
  1553. {
  1554.     if(toupper(c) >= 65 && toupper(c) <= 92)
  1555.         return 1;
  1556.     else
  1557.         return 0;
  1558. }
  1559.  
  1560. void Tradutor(FILE *PtrPal)
  1561. {
  1562.     TpPalavra Pal;
  1563.     int Pos, i, Aux;
  1564.     char Frase[1000], StrAux[1000], Traducao[1000];
  1565.    
  1566.     system("cls");
  1567.    
  1568.     Cabecalho("Tradutor");
  1569.    
  1570.     PtrPal = fopen("Palavra.dat", "rb");
  1571.    
  1572.     if(PtrPal == NULL)
  1573.     {
  1574.         gotoxy(30, 6);
  1575.         textcolor(4);
  1576.         printf("Arquivo de palavras inexistente");
  1577.         textcolor(15);
  1578.     }
  1579.     else
  1580.     {
  1581.         gotoxy(2, 4);
  1582.         printf("Texto em ingles:");
  1583.         fflush(stdin);
  1584.         gets(Frase);
  1585.        
  1586.         while(strcmp(Frase, "\0") != 0)
  1587.         {
  1588.             strcpy(Traducao, "\0");
  1589.            
  1590.             Aux = 0;
  1591.            
  1592.             for(i = 0; i <= strlen(Frase); i++)
  1593.             {
  1594.                 if(ELetra(Frase[i]) == 1)
  1595.                     StrAux[Aux++] = Frase[i];
  1596.                 else if(i > 0 && Frase[i] == ' ' || Frase[i] == '\0' && ELetra(Frase[i - 1]) == 1)
  1597.                 {
  1598.                     StrAux[Aux] = '\0';
  1599.                    
  1600.                     Pos = BuscaPalavraIngles(PtrPal, StrAux);
  1601.                                    
  1602.                     if(Pos == -1)
  1603.                     {
  1604.                         strcat(Traducao, StrAux);
  1605.                         strcat(Traducao, " ");
  1606.                     }
  1607.                     else
  1608.                     {
  1609.                         fseek(PtrPal, Pos, 0);
  1610.                         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  1611.                        
  1612.                         strcat(Traducao, Pal.port);
  1613.                         strcat(Traducao, " ");
  1614.                     }
  1615.                    
  1616.                     strcpy(StrAux, "\0");
  1617.                     Aux = 0;
  1618.                 }
  1619.             }
  1620.            
  1621.             gotoxy(2, 5);
  1622.             printf("Traducao: %s", Traducao);
  1623.            
  1624.             getch();
  1625.            
  1626.             system("cls");
  1627.             Cabecalho("Tradutor");
  1628.            
  1629.             gotoxy(2, 4);
  1630.             printf("Texto em ingles:");
  1631.             fflush(stdin);
  1632.             gets(Frase);
  1633.         }
  1634.     }
  1635.    
  1636.     fclose(PtrPal);
  1637. }
  1638.  
  1639. void InsercaoAutomatica(FILE *PtrPes, FILE *PtrPal)
  1640. {
  1641.     int NumRPes, NumRPal, i;
  1642.     time_t t = time(NULL);
  1643.     struct tm tm = *localtime(&t);
  1644.    
  1645.     TpPessoa VetPessoa[5] = {{"Joao Victor", "jvsierra", 12345, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1646.                             {"Rafael", "rafa", 45678, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1647.                             {"Miranda", "mir23", 12458, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1648.                             {"Arthur", "art657", 41256, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}},
  1649.                             {"Sofia", "sf123", 13879, 0, 1, {tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900}}};
  1650.                            
  1651.     TpPalavra VetPalavra[5] = {"lapis", "pencil", "Instrumento usado para escrever", 10, 1};
  1652.    
  1653.    
  1654.     system("cls");
  1655.     Cabecalho("Insercao Automatica");
  1656.    
  1657.     PtrPes = fopen("Pessoa.dat", "ab+");
  1658.     PtrPal = fopen("Palavra.dat", "ab+");
  1659.    
  1660.     fseek(PtrPes, 0, 2);
  1661.     NumRPes = ftell(PtrPes) / sizeof(TpPessoa);
  1662.     fseek(PtrPal, 0, 2);
  1663.     NumRPal = ftell(PtrPal) / sizeof(TpPalavra);
  1664.    
  1665.     if(NumRPes > 0 || NumRPal > 0)
  1666.     {
  1667.         gotoxy(30, 6);
  1668.         textcolor(4);
  1669.         printf("Os arquivos ja contem dados");
  1670.         textcolor(15);
  1671.         fclose(PtrPal);
  1672.     }
  1673.     else
  1674.     {
  1675.         fwrite(VetPessoa, sizeof(TpPessoa), 5, PtrPes);
  1676.         fwrite(&VetPalavra[0], sizeof(TpPalavra), 1, PtrPal);
  1677.        
  1678.         gotoxy(30, 6);
  1679.         textcolor(2);
  1680.         printf("Dados inseridos");
  1681.         textcolor(15);
  1682.     }
  1683.    
  1684.     fclose(PtrPes);
  1685.     fclose(PtrPal);
  1686.     SelecaoDiretaPessoa(PtrPes);
  1687.    
  1688.     getch();
  1689. }
  1690.  
  1691. int TemLetraPalavra(char Palavra[40], char Letra)
  1692. {
  1693.     int i = 0;
  1694.    
  1695.     while(i < strlen(Palavra) && Palavra[i] != Letra)
  1696.         i++;
  1697.        
  1698.     if(i < strlen(Palavra))
  1699.         return i;
  1700.     else
  1701.         return -1;
  1702. }
  1703.  
  1704. void OrdenaJogadoresPontuacao(FILE *PtrPes)
  1705. {
  1706.     int a, NumR;
  1707.     TpPessoa RegA, RegB;
  1708.    
  1709.     PtrPes = fopen("Pessoa.dat", "rb+");
  1710.    
  1711.     fseek(PtrPes, 0, 2);
  1712.     NumR = ftell(PtrPes) / sizeof(TpPessoa);
  1713.    
  1714.     while(NumR > 0)
  1715.     {
  1716.         for(a = 0; a < NumR - 1; a++)
  1717.         {
  1718.             fseek(PtrPes, a * sizeof(TpPessoa), 0);
  1719.             fread(&RegA, sizeof(TpPessoa), 1, PtrPes); 
  1720.             fread(&RegB, sizeof(TpPessoa), 1, PtrPes); 
  1721.            
  1722.             if(RegA.pont < RegB.pont)
  1723.             {
  1724.                 fseek(PtrPes, a * sizeof(TpPessoa), 0);
  1725.                 fwrite(&RegB, sizeof(TpPessoa), 1, PtrPes);
  1726.                 fwrite(&RegA, sizeof(TpPessoa), 1, PtrPes);
  1727.             }
  1728.         }  
  1729.        
  1730.         NumR--;
  1731.     }
  1732.    
  1733.     fclose(PtrPes);
  1734. }
  1735.  
  1736. void RankingJogadores(FILE *PtrPes)
  1737. {
  1738.     int linha = 5;
  1739.     TpPessoa Pes;
  1740.    
  1741.     system("cls");
  1742.    
  1743.     QuadroFlexivel(1, 1, 80, 3);
  1744.     gotoxy(30, 2);
  1745.     printf("Ranking dos Jogadores");
  1746.    
  1747.     PtrPes = fopen("Pessoa.dat", "rb");
  1748.    
  1749.     if(PtrPes == NULL)
  1750.     {
  1751.         gotoxy(30, 6);
  1752.         textcolor(4);
  1753.         printf("Arquivo de jogadores inexistente");
  1754.         textcolor(15);
  1755.     }
  1756.     else
  1757.     {
  1758.         OrdenaJogadoresPontuacao(PtrPes);
  1759.        
  1760.         rewind(PtrPes);
  1761.         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1762.        
  1763.         while(!feof(PtrPes))
  1764.         {
  1765.             if(Pes.status == 1)
  1766.             {
  1767.                 ImprimePessoa(Pes, linha);
  1768.                 linha += 6;
  1769.             }
  1770.            
  1771.             fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  1772.         }
  1773.        
  1774.         gotoxy(1, 1);
  1775.     }
  1776.    
  1777.     fclose(PtrPes);
  1778.    
  1779.     getch();
  1780. }
  1781.  
  1782. void ImprimeJogada(TpPalavForca Jog, int linha)
  1783. {
  1784.     QuadroFlexivel(2, linha - 1, 79, linha + 4);
  1785.     gotoxy(3, linha++);
  1786.     textcolor(14);
  1787.     printf("Login: ");
  1788.     textcolor(15);
  1789.     printf("%s", Jog.Login);
  1790.     gotoxy(4, linha++);
  1791.     textcolor(14);
  1792.     printf("Palavra: ");
  1793.     textcolor(15);
  1794.     printf("%s", Jog.Palavra);
  1795.     gotoxy(4, linha);
  1796.     textcolor(14);
  1797.  
  1798.     if(Jog.Acertou == 0)
  1799.         printf("Jogador perdeu");
  1800.     else
  1801.         printf("Joador ganhou");
  1802.        
  1803.     textcolor(15);
  1804. }
  1805.  
  1806. void ConsultaJogadas(FILE *PtrPalavForca)
  1807. {
  1808.     TpPalavForca PalForca;
  1809.     char loginAux[10];
  1810.     int linha = 7, Pos;
  1811.    
  1812.     system("cls");
  1813.    
  1814.     QuadroFlexivel(1, 1, 80, 3);
  1815.     gotoxy(30, 2);
  1816.     printf("Consulta de Jogadas");
  1817.    
  1818.     PtrPalavForca = fopen("PalavraForca.dat", "rb");
  1819.    
  1820.     if(PtrPalavForca == NULL)
  1821.     {
  1822.         gotoxy(30, 6);
  1823.         textcolor(4);
  1824.         printf("Arquivo de jogadas inexistente");
  1825.         textcolor(15);
  1826.     }
  1827.     else
  1828.     {
  1829.         gotoxy(2, 5);
  1830.         printf("Digite o login: ");
  1831.         fflush(stdin);
  1832.         gets(loginAux);
  1833.        
  1834.         while(strcmp(loginAux, "\0") != 0)
  1835.         {
  1836.             rewind(PtrPalavForca);
  1837.            
  1838.             fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
  1839.            
  1840.             while(!feof(PtrPalavForca))
  1841.             {
  1842.                 if(strcmp(PalForca.Login, loginAux) == 0)
  1843.                 {
  1844.                     ImprimeJogada(PalForca, linha);
  1845.                     linha += 6;
  1846.                 }
  1847.                
  1848.                 fread(&PalForca, sizeof(TpPalavForca), 1, PtrPalavForca);
  1849.             }
  1850.            
  1851.             gotoxy(20, linha);
  1852.             printf("Relatorio concluido");
  1853.             gotoxy(1, 1);
  1854.            
  1855.             getch();
  1856.            
  1857.             system("cls");
  1858.             QuadroFlexivel(1, 1, 80, 3);
  1859.             gotoxy(30, 2);
  1860.             printf("Consulta de Jogadas");
  1861.             gotoxy(2, 5);
  1862.             printf("Digite o login: ");
  1863.             fflush(stdin);
  1864.             gets(loginAux);
  1865.         }
  1866.     }
  1867.    
  1868.     fclose(PtrPalavForca);
  1869.     getch();
  1870. }
  1871.  
  1872. int UsuarioGanhou(char Letras[40], char Palavra[40])
  1873. {
  1874.     int i, Cont = 0;
  1875.    
  1876.     for(i = 0; i < strlen(Palavra); i++)
  1877.         if(TemLetraPalavra(Letras, Palavra[i]) >= 0)
  1878.             Cont++;
  1879.            
  1880.     if(Cont == strlen(Palavra))
  1881.         return 1;
  1882.     else
  1883.         return 0;
  1884. }
  1885.  
  1886. void Desenha(char Palavra[40], char LetrasCorretas[40], int NumErros)
  1887. {
  1888.     int i, j;
  1889.    
  1890.     textcolor(14);
  1891.    
  1892.     gotoxy(45, 5);
  1893.     printf("Chances restantes: ");
  1894.     textcolor(15);
  1895.     printf("%d", 6 - NumErros);
  1896.    
  1897.     textcolor(14);
  1898.     if(NumErros >= 1)
  1899.     {
  1900.         gotoxy(30, 10);
  1901.         printf("%c", 2);
  1902.     }
  1903.     if(NumErros >= 2)
  1904.     {
  1905.         gotoxy(30, 11);
  1906.         printf("%c", '|');
  1907.     }
  1908.     if(NumErros >= 3)
  1909.     {
  1910.         gotoxy(29,11);
  1911.         printf("%c", '/');
  1912.     }
  1913.     if(NumErros >= 4)
  1914.     {
  1915.         gotoxy(31,11);
  1916.         printf("%c", '\\');
  1917.     }
  1918.     if(NumErros >= 5)
  1919.     {
  1920.         gotoxy(29,12);
  1921.         printf("%c", '/');
  1922.     }  
  1923.     if(NumErros >= 6)
  1924.     {
  1925.         gotoxy(31,12);
  1926.         printf("%c", '\\');
  1927.     }
  1928.    
  1929.     textcolor(15);
  1930.     for(i = 0; i < strlen(Palavra); i++)
  1931.     {
  1932.         gotoxy((i+2) * 5, 15);
  1933.         printf("___");
  1934.     }
  1935.    
  1936.     textcolor(14);
  1937.     gotoxy(2, 6);
  1938.     textcolor(14);
  1939.     printf("Letras ja colocadas: ");
  1940.     gotoxy(25, 6);
  1941.                        
  1942.     for(i = 0; i < strlen(LetrasCorretas); i++)
  1943.         printf("%c ", LetrasCorretas[i]);
  1944.    
  1945.     for(i = 0; LetrasCorretas[i] != '\0'; i++)
  1946.     {
  1947.         for(j = 0; j < strlen(Palavra); j++)
  1948.             if(toupper(Palavra[j]) == toupper(LetrasCorretas[i]))
  1949.             {
  1950.                 gotoxy((j + 2) * 5, 14);
  1951.                 printf("%c", LetrasCorretas[i]);
  1952.             }
  1953.     }
  1954.    
  1955.     textcolor(15);
  1956.  
  1957.     gotoxy(20, 10);
  1958. }
  1959.  
  1960. int BuscaJogada(FILE *PtrJogada, char login[10], char palavra[40])
  1961. {
  1962.     int i = 0;
  1963.     TpPalavForca Reg;
  1964.    
  1965.     rewind(PtrJogada);
  1966.    
  1967.     fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
  1968.    
  1969.     while(!feof(PtrJogada) && (strcmp(Reg.Login, login) != 0 || strcmp(Reg.Palavra, palavra) != 0))
  1970.         fread(&Reg, sizeof(TpPalavForca), 1, PtrJogada);
  1971.        
  1972.     if(!feof(PtrJogada))
  1973.         return ftell(PtrJogada) - sizeof(TpPalavForca);
  1974.     else
  1975.         return -1;
  1976. }
  1977.  
  1978. void JogoForca(FILE *PtrPes, FILE *PtrPal)
  1979. {
  1980.     FILE *PtrPalForca;
  1981.     TpPalavForca PalForca;
  1982.     TpPessoa Pes;
  1983.     TpPalavra Pal;
  1984.     int Pos, NumR, SenhaAux, UsuarioLogado = 0;
  1985.     int PosPalavra, Lingua, NumTentativas, TLLetras, Ganhou, i;
  1986.     char Letra, PalavraSorteada[40], VetLetras[40];
  1987.  
  1988.     system("cls");
  1989.     Cabecalho("Jogo da Forca");
  1990.    
  1991.     PtrPes = fopen("Pessoa.dat", "rb+");
  1992.    
  1993.     if(PtrPes == NULL)
  1994.     {
  1995.         gotoxy(30, 6);
  1996.         textcolor(4);
  1997.         printf("Arquivo de pessoas inexistente");
  1998.         textcolor(15);
  1999.     }
  2000.     else
  2001.     {
  2002.         PtrPal = fopen("Palavra.dat", "rb");
  2003.    
  2004.         if(PtrPal == NULL)
  2005.         {
  2006.             gotoxy(30, 6);
  2007.             textcolor(4);
  2008.             printf("Arquivo de palavras inexistente");
  2009.             textcolor(15);
  2010.         }
  2011.         else
  2012.         {
  2013.             fseek(PtrPal, 0, 2);
  2014.             NumR = ftell(PtrPal) / sizeof(TpPalavra);
  2015.            
  2016.             if(NumR == 0)
  2017.             {
  2018.                 gotoxy(30, 6);
  2019.                 textcolor(4);
  2020.                 printf("Nenhuma palavra cadastrada");
  2021.                 textcolor(15);
  2022.             }  
  2023.             else
  2024.             {  
  2025.                 do
  2026.                 {
  2027.                     system("cls");
  2028.                     Cabecalho("Jogo da Forca");
  2029.                    
  2030.                     gotoxy(2, 4);
  2031.                     printf("Login: ");
  2032.                     fflush(stdin);
  2033.                     gets(Pes.login);
  2034.                     gotoxy(2, 5);
  2035.                     printf("Senha: ");
  2036.                     textcolor(0);
  2037.                     scanf("%d", &SenhaAux);
  2038.                     textcolor(15);
  2039.                    
  2040.                     Pos = BuscaExaustivaPessoa(PtrPes, Pes.login);
  2041.                    
  2042.                     if(Pos == -1)
  2043.                     {
  2044.                         gotoxy(30, 6);
  2045.                         textcolor(4);
  2046.                         printf("Login inexistente");
  2047.                         textcolor(15);
  2048.                     }
  2049.                     else
  2050.                     {
  2051.                         fseek(PtrPes, Pos, 0);
  2052.                         fread(&Pes, sizeof(TpPessoa), 1, PtrPes);
  2053.                        
  2054.                         if(Pes.senha != SenhaAux)
  2055.                         {
  2056.                             gotoxy(30, 6);
  2057.                             textcolor(4);
  2058.                             printf("Senha errada");
  2059.                             textcolor(15);
  2060.                         }
  2061.                         else
  2062.                             UsuarioLogado = 1;
  2063.                     }
  2064.                    
  2065.                     getch();
  2066.                 }while(strcmp(Pes.login, "\0") != 0 && UsuarioLogado == 0);
  2067.             }
  2068.            
  2069.            
  2070.             if(UsuarioLogado == 1)
  2071.             {
  2072.                 PtrPalForca = fopen("PalavraForca.dat", "ab+");
  2073.                
  2074.                 do
  2075.                 {
  2076.                     system("cls");
  2077.                     Cabecalho("Jogo da forca");
  2078.  
  2079.                     do
  2080.                     {
  2081.                         Lingua = rand() % 2;
  2082.                         PosPalavra = rand() % NumR;
  2083.                         fseek(PtrPal, PosPalavra * sizeof(TpPalavra), 0);
  2084.                         fread(&Pal, sizeof(TpPalavra), 1, PtrPal);
  2085.                
  2086.                         if(Lingua == 0)
  2087.                             strcpy(PalavraSorteada, Pal.port);
  2088.                         else
  2089.                             strcpy(PalavraSorteada, Pal.ing);
  2090.                            
  2091.                         gotoxy(30, 18);
  2092.                         printf("%d", NumR);
  2093.                     }while(BuscaJogada(PtrPalForca, Pes.login, PalavraSorteada) != -1);
  2094.    
  2095.                     NumTentativas = 6;
  2096.                     strcpy(VetLetras, "\0");
  2097.                     TLLetras = 0;
  2098.                    
  2099.                     while(NumTentativas > 0 && UsuarioGanhou(VetLetras, PalavraSorteada) == 0)
  2100.                     {
  2101.                         system("cls");
  2102.                         Cabecalho("Jogo da forca");
  2103.                    
  2104.                         gotoxy(2, 4);
  2105.                         textcolor(14);
  2106.                         printf("Dica: ");
  2107.                         textcolor(15);
  2108.                         printf("%s", Pal.significado);
  2109.                         gotoxy(2, 5);
  2110.                         textcolor(14);
  2111.                         printf("Lingua: ");
  2112.                         textcolor(15);
  2113.                         if(Lingua == 0)
  2114.                             printf("Portugues");
  2115.                         else
  2116.                             printf("Ingles");
  2117.                        
  2118.                         Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
  2119.                        
  2120.                         gotoxy(2, 7);  
  2121.                         printf("Digite uma letra: ");
  2122.                         fflush(stdin);
  2123.                         Letra = getche();
  2124.                        
  2125.                         if(TemLetraPalavra(VetLetras, Letra) >= 0)
  2126.                         {
  2127.                             gotoxy(30, 8);
  2128.                             textcolor(14);
  2129.                             printf("Voce ja usou essa letra!");
  2130.                         }
  2131.                         else
  2132.                         {
  2133.                             gotoxy(30, 8);
  2134.                             if(TemLetraPalavra(PalavraSorteada, Letra) >= 0)
  2135.                             {
  2136.                                 textcolor(2);
  2137.                                 printf("Acertou a letra");
  2138.                                 textcolor(15);
  2139.                             }
  2140.                             else
  2141.                             {
  2142.                                 textcolor(4);
  2143.                                 printf("Errou a letra");
  2144.                                 textcolor(15);
  2145.                                 NumTentativas--;
  2146.                             }
  2147.                            
  2148.                             VetLetras[TLLetras++] = Letra;
  2149.                             VetLetras[TLLetras] = '\0';
  2150.                         }
  2151.                        
  2152.                         getch();
  2153.                     }
  2154.                    
  2155.                     Desenha(PalavraSorteada, VetLetras, 6 - NumTentativas);
  2156.                    
  2157.                     if(NumTentativas == 0)
  2158.                     {
  2159.                         textcolor(4);
  2160.                         gotoxy(2, 17);
  2161.                         printf("Voce perdeu! A palavra era: %s", PalavraSorteada);
  2162.                         Ganhou = 0;
  2163.                     }
  2164.                     else
  2165.                     {
  2166.                         Pes.pont += Pal.pont;
  2167.                         fseek(PtrPes, Pos, 0);
  2168.                         fwrite(&Pes, sizeof(TpPessoa), 1, PtrPes);
  2169.                         Ganhou = 1;
  2170.                        
  2171.                         textcolor(2);
  2172.                         gotoxy(2, 17);
  2173.                         printf("Voce ganhou!");
  2174.                     }
  2175.                    
  2176.                     PalForca.Acertou = Ganhou;
  2177.                     strcpy(PalForca.Login, Pes.login);
  2178.                     strcpy(PalForca.Palavra, PalavraSorteada);
  2179.                     fwrite(&PalForca, sizeof(TpPalavForca), 1, PtrPalForca);
  2180.                    
  2181.                     gotoxy(2, 18);
  2182.                     textcolor(14);
  2183.                     printf("Deseja jogar novamente? (S/N):");
  2184.                     textcolor(15);
  2185.                 }while(toupper(getche()) == 'S');
  2186.                
  2187.                 fclose(PtrPalForca);
  2188.             }
  2189.         }
  2190.        
  2191.         fclose(PtrPal);
  2192.     }
  2193.    
  2194.     fclose(PtrPes);
  2195.    
  2196.     getch();
  2197. }
  2198.  
  2199. char Menu(void)
  2200. {
  2201.     int i;
  2202.    
  2203.     system("cls");
  2204.     Quadro();
  2205.    
  2206.     textcolor(14);
  2207.    
  2208.     gotoxy(27, 2);
  2209.     printf("ATP 2 - JOGO DA FORCA\n");
  2210.    
  2211.     for(i = 2; i <= 79; i++)
  2212.     {
  2213.         gotoxy(i, 3);
  2214.         printf("%c", 205);
  2215.     }
  2216.    
  2217.     textbackground(4);
  2218.    
  2219.     gotoxy(4, 4);
  2220.     printf("      MENU DE PALAVRAS           ");
  2221.    
  2222.     gotoxy(4, 5);
  2223.     printf("[A] - Cadastrar palavras         ");
  2224.     gotoxy(4, 6);
  2225.     printf("[B] - Relatorio de palavras      ");
  2226.     gotoxy(4, 7);
  2227.     printf("[C] - Alteracao de palavras      ");
  2228.     gotoxy(4, 8);
  2229.     printf("[D] - Consulta de palavras       ");
  2230.     gotoxy(4, 9);
  2231.     printf("[E] - Exclusao Fisica de Palavras");
  2232.     gotoxy(4, 10);
  2233.     printf("[F] - Exclusao Logica de Palavras");
  2234.     gotoxy(4, 11);
  2235.     printf("[G] - Ordenar Palavras           ");
  2236.    
  2237.     gotoxy(40, 4);
  2238.     printf("      MENU DE PESSOAS            ");
  2239.     gotoxy(40, 5);
  2240.     printf("[H] - Cadastrar pessoas          ");
  2241.     gotoxy(40, 6);
  2242.     printf("[I] - Relatorio de pessoas       ");
  2243.     gotoxy(40, 7);
  2244.     printf("[J] - Alteracao de pessoas       ");
  2245.     gotoxy(40, 8);
  2246.     printf("[K] - Consulta de pessoas        ");
  2247.     gotoxy(40, 9);
  2248.     printf("[L] - Exclusao Fisica de Pessoas ");
  2249.     gotoxy(40, 10);
  2250.     printf("[M] - Exclusao Logica de Pessoas ");
  2251.     gotoxy(40, 11);
  2252.     printf("[N] - Ordenar Pessoas Por Nome   ");
  2253.    
  2254.     gotoxy(25, 13);
  2255.     printf("            MENU GERAL           ");
  2256.    
  2257.     gotoxy(4, 15);
  2258.     printf("[O] - JOGAR FORCA                ");
  2259.     gotoxy(40, 15);
  2260.     printf("[P] - Tradutor de frases         ");
  2261.     gotoxy(4, 16);
  2262.     printf("[Q] - Insercao Automatica        ");
  2263.     gotoxy(40, 16);
  2264.     printf("[R] - Ranking dos Jogadores      ");
  2265.    
  2266.     gotoxy(4, 19);
  2267.     printf("[ESC] - Sair                     ");
  2268.    
  2269.     gotoxy(40, 19);
  2270.     printf("[S] - Consulta de jogadas        ");
  2271.    
  2272.     textbackground(0);
  2273.     textcolor(7);
  2274.    
  2275.     return toupper(getche());
  2276. }
  2277.  
  2278. void TestaBusca(FILE *PtrPes)
  2279. {
  2280.     system("cls");
  2281.     PtrPes = fopen("Pessoa.dat", "rb+");
  2282.     char login[10];
  2283.     fflush(stdin);
  2284.     gets(login);
  2285.    
  2286.     printf("\n%d", BuscaSentinelaPessoa(PtrPes, login));
  2287.     fclose(PtrPes);
  2288.     getch();
  2289. }
  2290.  
  2291. void Executa(void)
  2292. {
  2293.     char Op;
  2294.     FILE *PtrArq, *PtrPes, *PtrPalavForca;
  2295.    
  2296.     //TestaBusca(PtrPes);
  2297.    
  2298.     Op = Menu();
  2299.    
  2300.     while(Op != 27)
  2301.     {
  2302.         switch(Op)
  2303.         {
  2304.             case 'A':
  2305.                 CadastraPalavra(PtrArq);
  2306.             break;
  2307.             case 'B':
  2308.                 RelatorioPalavras(PtrArq);
  2309.             break;
  2310.             case 'C':
  2311.                 AlteracaoPalavra(PtrArq);
  2312.             break;
  2313.             case 'D':
  2314.                 ConsultaPalavras(PtrArq);
  2315.             break;
  2316.             case 'E':
  2317.                 ExclusaoFisicaPalavra(PtrArq);
  2318.             break;
  2319.             case 'F':
  2320.                 ExclusaoLogicaPalavra(PtrArq);
  2321.             break;
  2322.             case 'G':
  2323.                 BubbleSortPalavra(PtrArq);
  2324.                
  2325.                 system("cls");
  2326.                 gotoxy(40, 2);
  2327.                 printf("Palavras ordenadas");
  2328.                 getch();
  2329.             break;
  2330.             case 'H':
  2331.                 CadastraPessoa(PtrPes);
  2332.             break;
  2333.             case 'I':
  2334.                 RelatorioPessoa(PtrPes);
  2335.             break;
  2336.             case 'J':
  2337.                 AlteracaoPessoa(PtrPes);
  2338.             break;
  2339.             case 'K':
  2340.                 ConsultaPessoa(PtrPes);
  2341.             break;
  2342.             case 'L':
  2343.                 ExclusaoFisicaPessoa(PtrPes);
  2344.             break;
  2345.             case 'M':
  2346.                 ExclusaoLogicaPessoa(PtrPes);
  2347.             break;
  2348.             case 'N':
  2349.                 BubbleSortPessoa(PtrPes);
  2350.                
  2351.                 system("cls");
  2352.                 gotoxy(40, 2);
  2353.                 printf("Pessoas ordenadas");
  2354.                 getch();
  2355.             break;
  2356.             case 'O':
  2357.                 JogoForca(PtrPes, PtrArq);
  2358.             break;
  2359.             case 'P':
  2360.                 Tradutor(PtrArq);
  2361.             break;
  2362.             case 'Q':
  2363.                 InsercaoAutomatica(PtrPes, PtrArq);
  2364.             break;
  2365.             case 'R':
  2366.                 RankingJogadores(PtrPes);
  2367.             break;
  2368.             case 'S':
  2369.                 ConsultaJogadas(PtrPalavForca);
  2370.             break;
  2371.             default:
  2372.                 printf("Opcao invalida\n");
  2373.                 getch();
  2374.             break;
  2375.         }
  2376.    
  2377.        
  2378.         Op = Menu();
  2379.     }
  2380.    
  2381.     getch();
  2382. }
  2383.  
  2384. int main(void)
  2385. {
  2386.     srand(time(NULL));
  2387.    
  2388.     Executa();
  2389.    
  2390.     return 1;
  2391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement