Advertisement
Jvsierra

Trabalho de ATP quase pronto

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