Advertisement
Jvsierra

ATP

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