Jvsierra

12

Feb 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6.  
  7. #define LIM 101
  8.  
  9. struct TpData
  10. {
  11. int dia, mes, ano;
  12. };
  13.  
  14. struct TpAposta
  15. {
  16. int CodAposta, Numeros[7];
  17. TpData Data;
  18. };
  19.  
  20. void LeArquivo(char NomeArq[LIM])
  21. {
  22. FILE *PtrTxt;
  23. char L;
  24.  
  25. system("cls");
  26.  
  27. printf("Leitura de arquivo\n\n");
  28.  
  29. PtrTxt = fopen(NomeArq, "r");
  30.  
  31. if(PtrTxt == NULL)
  32. printf("Arquivo %s inexistente\n\n", NomeArq);
  33. else
  34. {
  35. printf("---------------------------------------\n");
  36.  
  37. L = fgetc(PtrTxt);
  38.  
  39. while(!feof(PtrTxt))
  40. {
  41. printf("%c", L);
  42.  
  43. L = fgetc(PtrTxt);
  44. }
  45.  
  46. printf("\n---------------------------------------\n\n");
  47.  
  48. printf("Leitura concluida\n\n");
  49.  
  50. fclose(PtrTxt);
  51. }
  52.  
  53. getch();
  54. }
  55.  
  56. int ComparaArquivos(char NomeArq1[LIM], char NomeArq2[LIM])
  57. {
  58. int ret;
  59. char L1, L2;
  60. FILE *PtrTxt;
  61.  
  62. PtrTxt = fopen(NomeArq1, "r");
  63.  
  64. if(PtrTxt == NULL)
  65. ret = -1;
  66. else
  67. {
  68. FILE *PtrAux = fopen(NomeArq2, "r");
  69.  
  70. if(PtrAux == NULL)
  71. ret = -1;
  72. else
  73. {
  74. L1 = fgetc(PtrTxt);
  75. L2 = fgetc(PtrAux);
  76.  
  77. while(!feof(PtrTxt) && L1 == L2)
  78. {
  79. L1 = fgetc(PtrTxt);
  80. L2 = fgetc(PtrAux);
  81. }
  82.  
  83. if(L1 == L2)
  84. ret = 1;
  85. else
  86. ret = 0;
  87. }
  88. }
  89.  
  90. return ret;
  91. }
  92.  
  93. void ArquivoMaiusculas(char NomeArq[LIM])
  94. {
  95. char Letra;
  96. FILE *PtrTxt;
  97.  
  98. system("cls");
  99.  
  100. printf("Transformar letras de um arquivo para maiusculas\n\n");
  101.  
  102. PtrTxt = fopen(NomeArq, "r");
  103.  
  104. if(PtrTxt == NULL)
  105. printf("Arquivo %s inexistente\n\n", NomeArq);
  106. else
  107. {
  108. FILE *PtrAux = fopen("ARQUIVO_NOVO.txt", "w+");
  109.  
  110. Letra = toupper(getc(PtrTxt));
  111.  
  112. while(!feof(PtrTxt))
  113. {
  114. fputc(Letra, PtrAux);
  115.  
  116. Letra = toupper(getc(PtrTxt));
  117. }
  118.  
  119. fclose(PtrTxt);
  120. fclose(PtrAux);
  121.  
  122. printf("Processo concluido\n\n");
  123. }
  124.  
  125. getch();
  126. }
  127.  
  128. void GeraAposta(char NomeArq[LIM])
  129. {
  130. int i;
  131. TpAposta R;
  132. FILE *PtrTxt;
  133. time_t t = time(NULL);
  134. struct tm tm = *localtime(&t);
  135.  
  136. system("cls");
  137.  
  138. printf("Cadastrar apostas\n\n");
  139.  
  140. PtrTxt = fopen(NomeArq, "a");
  141.  
  142. printf("Digite o primerio dos 7 numeros:\n");
  143. scanf("%d", &R.Numeros[0]);
  144.  
  145. while(R.Numeros[0] > 0)
  146. {
  147. fseek(PtrTxt, 0, 2);
  148. R.CodAposta = ftell(PtrTxt) / 30 + 1;
  149.  
  150. for(i = 1; i < 7; i++)
  151. {
  152. printf("Digite o %do numero:\n", i + 1);
  153. scanf("%d", &R.Numeros[i]);
  154. }
  155.  
  156. R.Data.dia = tm.tm_mday;
  157. R.Data.mes = tm.tm_mon + 1;
  158. R.Data.ano = tm.tm_year + 1900;
  159.  
  160. fprintf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", R.CodAposta, R.Data.dia,
  161. R.Data.mes, R.Data.ano, R.Numeros[0], R.Numeros[1], R.Numeros[2], R.Numeros[3],
  162. R.Numeros[4], R.Numeros[5], R.Numeros[6]);
  163.  
  164. printf("\n\nAposta Cadastrada\n\n");
  165.  
  166. printf("Digite o primeiro dos 7 numeros:\n");
  167. scanf("%d", &R.Numeros[0]);
  168. }
  169.  
  170. fclose(PtrTxt);
  171. getch();
  172. }
  173.  
  174. void LeApostas(char NomeArq[100], int Dezenas[5])
  175. {
  176. int i;
  177. TpAposta R;
  178. FILE *PtrTxt;
  179. int Cont, TotQuinas, TotQuadras, TotTernos, Pos;
  180.  
  181. system("cls");
  182.  
  183. printf("\n\nLeitura de Apostas\n\n");
  184.  
  185. PtrTxt = fopen(NomeArq, "r");
  186.  
  187. if(PtrTxt == NULL)
  188. printf("Arquivo %s inexistente\n\n", NomeArq);
  189. else
  190. {
  191. TotQuinas = 0;
  192. TotQuadras = 0;
  193. TotTernos = 0;
  194.  
  195. fscanf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", &R.CodAposta, &R.Data.dia,
  196. &R.Data.mes, &R.Data.ano, &R.Numeros[0], &R.Numeros[1], &R.Numeros[2], &R.Numeros[3],
  197. &R.Numeros[4], &R.Numeros[5], &R.Numeros[6]);
  198.  
  199. while(!feof(PtrTxt))
  200. {
  201. Cont = 0;
  202.  
  203. for(i = 0; i < 7; i++)
  204. {
  205. Pos = 0;
  206.  
  207. while(Pos < 5 && Dezenas[Pos] != R.Numeros[i])
  208. Pos++;
  209.  
  210. if(Pos < 5)
  211. Cont++;
  212. }
  213.  
  214. if(Cont == 5)
  215. TotQuinas++;
  216. else if(Cont == 4)
  217. TotQuadras++;
  218. else if(Cont == 3)
  219. TotTernos++;
  220.  
  221. fscanf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", &R.CodAposta, &R.Data.dia,
  222. &R.Data.mes, &R.Data.ano, &R.Numeros[0], &R.Numeros[1], &R.Numeros[2], &R.Numeros[3],
  223. &R.Numeros[4], &R.Numeros[5], &R.Numeros[6]);
  224. }
  225.  
  226. fclose(PtrTxt);
  227.  
  228. printf("%d quinas\n", TotQuinas);
  229. printf("%d quadras\n", TotQuadras);
  230. printf("%d ternos\n", TotTernos);
  231. }
  232.  
  233. getch();
  234. }
  235.  
  236. void CriptografaArquivo(char NomeArq[100])
  237. {
  238. int Chave;
  239. char L, M;
  240. FILE *PtrTxt;
  241.  
  242. system("cls");
  243.  
  244. printf("Criptografar arquivo\n\n");
  245.  
  246. PtrTxt = fopen(NomeArq, "r");
  247.  
  248. if(PtrTxt == NULL)
  249. printf("Arquivo %s inexistente\n\n", NomeArq);
  250. else
  251. {
  252. do
  253. {
  254. printf("Chave de criptografia (1-26):\n");
  255. scanf("%d", &Chave);
  256. }while(Chave < 1 || Chave > 26);
  257.  
  258. FILE *PtrAux = fopen("Temp.txt", "a");
  259.  
  260. L = toupper(fgetc(PtrTxt));
  261.  
  262. while(!feof(PtrTxt))
  263. {
  264. if(L == ' ')
  265. M = '#';
  266. else if(L >= 65 && L <= 90)
  267. {
  268. M = L + Chave;
  269.  
  270. if(M > 90)
  271. M = 64 + (M - 90);
  272. }
  273. else
  274. M = L;
  275.  
  276. fputc(M, PtrAux);
  277.  
  278. L = toupper(fgetc(PtrTxt));
  279. }
  280.  
  281. fclose(PtrTxt);
  282. fclose(PtrAux);
  283. remove(NomeArq);
  284. rename("Temp.txt", NomeArq);
  285.  
  286. printf("\n\nProcesso Concluido\n\n");
  287. }
  288.  
  289. getch();
  290. }
  291.  
  292. void DescriptografaArquivo(char NomeArq[LIM])
  293. {
  294. int Chave;
  295. char L, M;
  296. FILE *PtrTxt;
  297.  
  298. system("cls");
  299.  
  300. printf("Criptografar arquivo\n\n");
  301.  
  302. PtrTxt = fopen(NomeArq, "r");
  303.  
  304. if(PtrTxt == NULL)
  305. printf("Arquivo %s inexistente\n\n", NomeArq);
  306. else
  307. {
  308. do
  309. {
  310. printf("Chave de criptografia (1-26):\n");
  311. scanf("%d", &Chave);
  312. }while(Chave < 1 || Chave > 26);
  313.  
  314. FILE *PtrAux = fopen("Temp.txt", "a");
  315.  
  316. L = toupper(fgetc(PtrTxt));
  317.  
  318. while(!feof(PtrTxt))
  319. {
  320. if(L >= 65 && L <= 90)
  321. {
  322. M = L - Chave;
  323.  
  324. if(M < 65)
  325. M = 90 - (64 - M);
  326. }
  327. else if(L == '#')
  328. M = ' ';
  329. else
  330. M = L;
  331.  
  332. fputc(M, PtrAux);
  333.  
  334. L = toupper(fgetc(PtrTxt));
  335. }
  336.  
  337. fclose(PtrTxt);
  338. fclose(PtrAux);
  339. remove(NomeArq);
  340. rename("Temp.txt", NomeArq);
  341.  
  342. printf("\n\nProcesso Concluido\n\n");
  343. }
  344.  
  345. getch();
  346. }
  347.  
  348. int QntdVogal(char NomeArq[100])
  349. {
  350. int Cont;
  351. char L;
  352. FILE *PtrTxt;
  353.  
  354. PtrTxt = fopen(NomeArq, "r");
  355.  
  356. if(PtrTxt == NULL)
  357. Cont = -1;
  358. else
  359. {
  360. Cont = 0;
  361.  
  362. L = toupper(fgetc(PtrTxt));
  363.  
  364. while(!feof(PtrTxt))
  365. {
  366. if(L == 'A' || L == '')
  367. }
  368.  
  369. fclose(PtrTxt);
  370. }
  371.  
  372. return Cont;
  373. }
  374.  
  375. void ContaLetras(char NomeArq[LIM])
  376. {
  377. int ContVogal, ContConsoante;
  378. int ContLinhas, ContCaracteres;
  379. char L;
  380. FILE *PtrTxt;
  381.  
  382. system("cls");
  383.  
  384. printf("Contador de caracteres\n\n");
  385.  
  386. PtrTxt = fopen(NomeArq, "r");
  387.  
  388. if(PtrTxt == NULL)
  389. printf("Arquivo %s inexistente\n\n", NomeArq);
  390. else
  391. {
  392. ContVogal = 0; ContConsoante = 0;
  393. ContLinhas = 0; ContCaracteres = 0;
  394.  
  395. L = toupper(fgetc(PtrTxt));
  396.  
  397. while(!feof(PtrTxt))
  398. {
  399. if(L >= 65 && L <= 90)
  400. {
  401. if(L == 'A' || L == 'E' || L == 'I' ||L == 'O' || L == 'U')
  402. ContVogal++;
  403. else
  404. ContConsoante++;
  405. }
  406. else if(L == 10)
  407. ContLinhas++;
  408.  
  409. ContCaracteres++;
  410.  
  411. L = toupper(fgetc(PtrTxt));
  412. }
  413. printf("%d vogais, %d consoantes\n", ContVogal, ContConsoante);
  414. printf("%d linhas\n", ContLinhas);
  415. printf("%d caracteres\n", ContCaracteres);
  416.  
  417. fclose(PtrTxt);
  418. }
  419.  
  420. getch();
  421. }
  422.  
  423. void ContaPalavra(char NomeArq[LIM], char Letra)
  424. {
  425. FILE *PtrTxt;
  426. int Cont, i;
  427. char LetraArq;
  428.  
  429. Letra = toupper(Letra);
  430.  
  431. system("cls");
  432.  
  433. printf("Contador de palavras\n\n");
  434.  
  435. PtrTxt = fopen(NomeArq, "r");
  436.  
  437. if(PtrTxt == NULL)
  438. printf("Arquivo %s inexistente\n\n", NomeArq);
  439. else
  440. {
  441. Cont = 0;
  442.  
  443. LetraArq = toupper(fgetc(PtrTxt));
  444.  
  445. if(LetraArq == Letra)
  446. Cont++;
  447.  
  448. while(!feof(PtrTxt))
  449. {
  450. if(LetraArq == ' ')
  451. {
  452. LetraArq = toupper(fgetc(PtrTxt));
  453.  
  454. if(LetraArq == Letra)
  455. Cont++;
  456. }
  457.  
  458. LetraArq = toupper(fgetc(PtrTxt));
  459. }
  460.  
  461. printf("%d palavras que comecam com %c\n", Cont, Letra);
  462.  
  463. fclose(PtrTxt);
  464. }
  465.  
  466. getch();
  467. }
  468.  
  469. void RemovePalavras(char NomeArq[LIM], char Letra)
  470. {
  471. FILE *PtrTxt;
  472. char LetraArq;
  473. int flag;
  474.  
  475. Letra = toupper(Letra);
  476.  
  477. system("cls");
  478.  
  479. printf("Remover palavras do arquivo\n\n");
  480.  
  481. PtrTxt = fopen(NomeArq, "r");
  482.  
  483. if(PtrTxt == NULL)
  484. printf("Arquivo %s inexistente\n\n", NomeArq);
  485. else
  486. {
  487. FILE *PtrAux = fopen("NOVO_ARQUIVO.txt", "a+");
  488.  
  489. flag = 0;
  490.  
  491. LetraArq = fgetc(PtrTxt);
  492.  
  493. if(toupper(LetraArq) != Letra)
  494. flag = 1;
  495.  
  496. while(!feof(PtrTxt))
  497. {
  498. if(LetraArq == ' ')
  499. {
  500. LetraArq = fgetc(PtrTxt);
  501.  
  502. if(toupper(LetraArq) != Letra)
  503. {
  504. flag = 1;
  505. fputc(' ', PtrAux);
  506. }
  507. else
  508. flag = 0;
  509. }
  510.  
  511. if(flag == 1)
  512. fputc(LetraArq, PtrAux);
  513.  
  514. LetraArq = fgetc(PtrTxt);
  515. }
  516.  
  517. fclose(PtrTxt);
  518. fclose(PtrAux);
  519.  
  520. printf("Palavras com a letra %c removidas\n\n", Letra);
  521. }
  522.  
  523. getch();
  524. }
  525.  
  526. void AtualizaVogais(char NomeArq[LIM])
  527. {
  528. int Pos;
  529. char L;
  530. FILE *PtrTxt;
  531.  
  532. system("cls");
  533.  
  534. printf("Trocar vogais por @\n\n");
  535.  
  536. PtrTxt = fopen(NomeArq, "r+");
  537.  
  538. if(PtrTxt == NULL)
  539. printf("Arquivo %s inexistente\n\n", NomeArq);
  540. else
  541. {
  542. Pos = 0;
  543. L = toupper(fgetc(PtrTxt));
  544.  
  545. while(!feof(PtrTxt))
  546. {
  547. fflush(PtrTxt);
  548.  
  549.  
  550. Pos++;
  551.  
  552. if(L == 'A' || L == 'E' || L == 'I' || L == 'O' || L == 'U')
  553. {
  554.  
  555. if(Pos == 1)
  556. fseek(PtrTxt, 0, 0);
  557. else
  558. fseek(PtrTxt, Pos - 1, 0);
  559.  
  560. fputc('@', PtrTxt);
  561. }
  562.  
  563. fseek(PtrTxt, Pos, 0);
  564. L = toupper(fgetc(PtrTxt));
  565. }
  566.  
  567. fclose(PtrTxt);
  568.  
  569. printf("\n\nProcesso concluido\n\n");
  570. }
  571.  
  572. getch();
  573. }
  574.  
  575. void NotepadClone(void)
  576. {
  577. int TL, i;
  578. char Texto[50][200], Aux[200], NomeArq[100];
  579. FILE *PtrTxt;
  580. system("cls");
  581.  
  582. printf("Escrever no arquivo\n\n");
  583.  
  584. printf("Digite o nome do arquivo:\n");
  585. fflush(stdin);
  586. gets(NomeArq);
  587.  
  588. TL = 0;
  589.  
  590. printf("Digite o conteudo da linha %d:\n", TL + 1);
  591. fflush(stdin);
  592. gets(Aux);
  593.  
  594. while(TL < 50 && strcmp(Aux, "FIM") != 0)
  595. {
  596. strcpy(Texto[TL++], Aux);
  597.  
  598. printf("\nDigite o conteudo da linha %d:\n", TL + 1);
  599. fflush(stdin);
  600. gets(Aux);
  601. }
  602.  
  603. PtrTxt = fopen(NomeArq, "a");
  604.  
  605. for(i = 0; i < TL; i++)
  606. {
  607. fputs(Texto[i], PtrTxt);
  608. fputc(10, PtrTxt);
  609. }
  610.  
  611. fclose(PtrTxt);
  612.  
  613. printf("\n\nGravacao realizada\n\n");
  614.  
  615. getch();
  616. }
  617.  
  618.  
  619. void CriptografaMesmoArquivo(char NomeArq[100])
  620. {
  621. int Chave, Pos;
  622. char L, M;
  623. FILE *PtrTxt;
  624.  
  625. system("cls");
  626.  
  627. PtrTxt = fopen(NomeArq, "r+");
  628.  
  629. if(PtrTxt == NULL)
  630. printf("Arquivo %s inexistente\n\n", NomeArq);
  631. else
  632. {
  633. do
  634. {
  635. printf("Chave de criptografia (1-26):\n");
  636. scanf("%d", &Chave);
  637. }while(Chave < 1 || Chave > 26);
  638.  
  639. L = toupper(fgetc(PtrTxt));
  640. Pos = 0;
  641.  
  642. while(!feof(PtrTxt))
  643. {
  644. fflush(PtrTxt);
  645.  
  646. fseek(PtrTxt, Pos, 0);
  647.  
  648. Pos++;
  649.  
  650. if(L == ' ')
  651. M = '#';
  652. else if(L >= 65 && L <= 90)
  653. {
  654. M = L + Chave;
  655.  
  656. if(M > 90)
  657. M = 64 + (M - 90);
  658. }
  659. else
  660.  
  661. fseek(PtrTxt, Pos - 2, 0);
  662.  
  663. fputc(M, PtrTxt);
  664.  
  665. fseek(PtrTxt, Pos, 0);
  666. L = toupper(fgetc(PtrTxt));
  667. }
  668.  
  669. fclose(PtrTxt);
  670.  
  671. printf("\n\nProcesso Concluido\n\n");
  672. }
  673.  
  674. getch();
  675. }
  676.  
  677. void SubstituiFgets(char NomeArq[100], char Palavra[100], char Sub[100])
  678. {
  679. int i, TL;
  680. char Linha[100], StrAux[100];
  681. FILE *PtrTxt;
  682.  
  683. system("cls");
  684.  
  685. printf("Substituir palavras\n\n");
  686.  
  687. PtrTxt = fopen(NomeArq, "r");
  688.  
  689. if(PtrTxt == NULL)
  690. printf("Arquivo %s inexistente\n\n", NomeArq);
  691. else
  692. {
  693. FILE *PtrAux = fopen("Temp.txt", "a");
  694.  
  695. strcpy(StrAux, "\0");
  696. TL = 0;
  697.  
  698. fgets(Linha, 100, PtrTxt);
  699.  
  700. while(!feof(PtrTxt))
  701. {
  702. for(i = 0; i < strlen(Linha); i++)
  703. {
  704. if(toupper(Linha[i]) >= 65 && toupper(Linha[i]) <= 90)
  705. StrAux[TL++] = Linha[i];
  706. else
  707. {
  708. StrAux[TL] = '\0';
  709.  
  710. if(stricmp(StrAux, Palavra) == 0)
  711. {
  712. strcpy(StrAux, Sub);
  713. TL = strlen(Sub);
  714.  
  715. StrAux[TL++] = Linha[i];
  716.  
  717. StrAux[TL] = '\0';
  718. }
  719. else
  720. {
  721. StrAux[TL++] = Linha[i];
  722. StrAux[TL] = '\0';
  723. }
  724.  
  725. fputs(StrAux, PtrAux);
  726.  
  727. strcpy(StrAux, "\0");
  728. TL = 0;
  729. }
  730. }
  731.  
  732. fgets(Linha, 100, PtrTxt);
  733. }
  734.  
  735. fputs("\n", PtrAux);
  736.  
  737. fclose(PtrTxt);
  738. fclose(PtrAux);
  739. remove(NomeArq);
  740. rename("Temp.txt", NomeArq);
  741.  
  742. printf("\n\nProcesso concluido\n\n");
  743. }
  744.  
  745. getch();
  746. }
Add Comment
Please, Sign In to add comment