Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <time.h>
- #define LIM 101
- struct TpData
- {
- int dia, mes, ano;
- };
- struct TpAposta
- {
- int CodAposta, Numeros[7];
- TpData Data;
- };
- void LeArquivo(char NomeArq[LIM])
- {
- FILE *PtrTxt;
- char L;
- system("cls");
- printf("Leitura de arquivo\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- printf("---------------------------------------\n");
- L = fgetc(PtrTxt);
- while(!feof(PtrTxt))
- {
- printf("%c", L);
- L = fgetc(PtrTxt);
- }
- printf("\n---------------------------------------\n\n");
- printf("Leitura concluida\n\n");
- fclose(PtrTxt);
- }
- getch();
- }
- int ComparaArquivos(char NomeArq1[LIM], char NomeArq2[LIM])
- {
- int ret;
- char L1, L2;
- FILE *PtrTxt;
- PtrTxt = fopen(NomeArq1, "r");
- if(PtrTxt == NULL)
- ret = -1;
- else
- {
- FILE *PtrAux = fopen(NomeArq2, "r");
- if(PtrAux == NULL)
- ret = -1;
- else
- {
- L1 = fgetc(PtrTxt);
- L2 = fgetc(PtrAux);
- while(!feof(PtrTxt) && L1 == L2)
- {
- L1 = fgetc(PtrTxt);
- L2 = fgetc(PtrAux);
- }
- if(L1 == L2)
- ret = 1;
- else
- ret = 0;
- }
- }
- return ret;
- }
- void ArquivoMaiusculas(char NomeArq[LIM])
- {
- char Letra;
- FILE *PtrTxt;
- system("cls");
- printf("Transformar letras de um arquivo para maiusculas\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- FILE *PtrAux = fopen("ARQUIVO_NOVO.txt", "w+");
- Letra = toupper(getc(PtrTxt));
- while(!feof(PtrTxt))
- {
- fputc(Letra, PtrAux);
- Letra = toupper(getc(PtrTxt));
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- printf("Processo concluido\n\n");
- }
- getch();
- }
- void GeraAposta(char NomeArq[LIM])
- {
- int i;
- TpAposta R;
- FILE *PtrTxt;
- time_t t = time(NULL);
- struct tm tm = *localtime(&t);
- system("cls");
- printf("Cadastrar apostas\n\n");
- PtrTxt = fopen(NomeArq, "a");
- printf("Digite o primerio dos 7 numeros:\n");
- scanf("%d", &R.Numeros[0]);
- while(R.Numeros[0] > 0)
- {
- fseek(PtrTxt, 0, 2);
- R.CodAposta = ftell(PtrTxt) / 30 + 1;
- for(i = 1; i < 7; i++)
- {
- printf("Digite o %do numero:\n", i + 1);
- scanf("%d", &R.Numeros[i]);
- }
- R.Data.dia = tm.tm_mday;
- R.Data.mes = tm.tm_mon + 1;
- R.Data.ano = tm.tm_year + 1900;
- fprintf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", R.CodAposta, R.Data.dia,
- R.Data.mes, R.Data.ano, R.Numeros[0], R.Numeros[1], R.Numeros[2], R.Numeros[3],
- R.Numeros[4], R.Numeros[5], R.Numeros[6]);
- printf("\n\nAposta Cadastrada\n\n");
- printf("Digite o primeiro dos 7 numeros:\n");
- scanf("%d", &R.Numeros[0]);
- }
- fclose(PtrTxt);
- getch();
- }
- void LeApostas(char NomeArq[100], int Dezenas[5])
- {
- int i;
- TpAposta R;
- FILE *PtrTxt;
- int Cont, TotQuinas, TotQuadras, TotTernos, Pos;
- system("cls");
- printf("\n\nLeitura de Apostas\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- TotQuinas = 0;
- TotQuadras = 0;
- TotTernos = 0;
- fscanf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", &R.CodAposta, &R.Data.dia,
- &R.Data.mes, &R.Data.ano, &R.Numeros[0], &R.Numeros[1], &R.Numeros[2], &R.Numeros[3],
- &R.Numeros[4], &R.Numeros[5], &R.Numeros[6]);
- while(!feof(PtrTxt))
- {
- Cont = 0;
- for(i = 0; i < 7; i++)
- {
- Pos = 0;
- while(Pos < 5 && Dezenas[Pos] != R.Numeros[i])
- Pos++;
- if(Pos < 5)
- Cont++;
- }
- if(Cont == 5)
- TotQuinas++;
- else if(Cont == 4)
- TotQuadras++;
- else if(Cont == 3)
- TotTernos++;
- fscanf(PtrTxt, "%d %d/%d/%d %d %d %d %d %d %d %d\n", &R.CodAposta, &R.Data.dia,
- &R.Data.mes, &R.Data.ano, &R.Numeros[0], &R.Numeros[1], &R.Numeros[2], &R.Numeros[3],
- &R.Numeros[4], &R.Numeros[5], &R.Numeros[6]);
- }
- fclose(PtrTxt);
- printf("%d quinas\n", TotQuinas);
- printf("%d quadras\n", TotQuadras);
- printf("%d ternos\n", TotTernos);
- }
- getch();
- }
- void CriptografaArquivo(char NomeArq[100])
- {
- int Chave;
- char L, M;
- FILE *PtrTxt;
- system("cls");
- printf("Criptografar arquivo\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- do
- {
- printf("Chave de criptografia (1-26):\n");
- scanf("%d", &Chave);
- }while(Chave < 1 || Chave > 26);
- FILE *PtrAux = fopen("Temp.txt", "a");
- L = toupper(fgetc(PtrTxt));
- while(!feof(PtrTxt))
- {
- if(L == ' ')
- M = '#';
- else if(L >= 65 && L <= 90)
- {
- M = L + Chave;
- if(M > 90)
- M = 64 + (M - 90);
- }
- else
- M = L;
- fputc(M, PtrAux);
- L = toupper(fgetc(PtrTxt));
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- remove(NomeArq);
- rename("Temp.txt", NomeArq);
- printf("\n\nProcesso Concluido\n\n");
- }
- getch();
- }
- void DescriptografaArquivo(char NomeArq[LIM])
- {
- int Chave;
- char L, M;
- FILE *PtrTxt;
- system("cls");
- printf("Criptografar arquivo\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- do
- {
- printf("Chave de criptografia (1-26):\n");
- scanf("%d", &Chave);
- }while(Chave < 1 || Chave > 26);
- FILE *PtrAux = fopen("Temp.txt", "a");
- L = toupper(fgetc(PtrTxt));
- while(!feof(PtrTxt))
- {
- if(L >= 65 && L <= 90)
- {
- M = L - Chave;
- if(M < 65)
- M = 90 - (64 - M);
- }
- else if(L == '#')
- M = ' ';
- else
- M = L;
- fputc(M, PtrAux);
- L = toupper(fgetc(PtrTxt));
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- remove(NomeArq);
- rename("Temp.txt", NomeArq);
- printf("\n\nProcesso Concluido\n\n");
- }
- getch();
- }
- int QntdVogal(char NomeArq[100])
- {
- int Cont;
- char L;
- FILE *PtrTxt;
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- Cont = -1;
- else
- {
- Cont = 0;
- L = toupper(fgetc(PtrTxt));
- while(!feof(PtrTxt))
- {
- if(L == 'A' || L == '')
- }
- fclose(PtrTxt);
- }
- return Cont;
- }
- void ContaLetras(char NomeArq[LIM])
- {
- int ContVogal, ContConsoante;
- int ContLinhas, ContCaracteres;
- char L;
- FILE *PtrTxt;
- system("cls");
- printf("Contador de caracteres\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- ContVogal = 0; ContConsoante = 0;
- ContLinhas = 0; ContCaracteres = 0;
- L = toupper(fgetc(PtrTxt));
- while(!feof(PtrTxt))
- {
- if(L >= 65 && L <= 90)
- {
- if(L == 'A' || L == 'E' || L == 'I' ||L == 'O' || L == 'U')
- ContVogal++;
- else
- ContConsoante++;
- }
- else if(L == 10)
- ContLinhas++;
- ContCaracteres++;
- L = toupper(fgetc(PtrTxt));
- }
- printf("%d vogais, %d consoantes\n", ContVogal, ContConsoante);
- printf("%d linhas\n", ContLinhas);
- printf("%d caracteres\n", ContCaracteres);
- fclose(PtrTxt);
- }
- getch();
- }
- void ContaPalavra(char NomeArq[LIM], char Letra)
- {
- FILE *PtrTxt;
- int Cont, i;
- char LetraArq;
- Letra = toupper(Letra);
- system("cls");
- printf("Contador de palavras\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- Cont = 0;
- LetraArq = toupper(fgetc(PtrTxt));
- if(LetraArq == Letra)
- Cont++;
- while(!feof(PtrTxt))
- {
- if(LetraArq == ' ')
- {
- LetraArq = toupper(fgetc(PtrTxt));
- if(LetraArq == Letra)
- Cont++;
- }
- LetraArq = toupper(fgetc(PtrTxt));
- }
- printf("%d palavras que comecam com %c\n", Cont, Letra);
- fclose(PtrTxt);
- }
- getch();
- }
- void RemovePalavras(char NomeArq[LIM], char Letra)
- {
- FILE *PtrTxt;
- char LetraArq;
- int flag;
- Letra = toupper(Letra);
- system("cls");
- printf("Remover palavras do arquivo\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- FILE *PtrAux = fopen("NOVO_ARQUIVO.txt", "a+");
- flag = 0;
- LetraArq = fgetc(PtrTxt);
- if(toupper(LetraArq) != Letra)
- flag = 1;
- while(!feof(PtrTxt))
- {
- if(LetraArq == ' ')
- {
- LetraArq = fgetc(PtrTxt);
- if(toupper(LetraArq) != Letra)
- {
- flag = 1;
- fputc(' ', PtrAux);
- }
- else
- flag = 0;
- }
- if(flag == 1)
- fputc(LetraArq, PtrAux);
- LetraArq = fgetc(PtrTxt);
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- printf("Palavras com a letra %c removidas\n\n", Letra);
- }
- getch();
- }
- void AtualizaVogais(char NomeArq[LIM])
- {
- int Pos;
- char L;
- FILE *PtrTxt;
- system("cls");
- printf("Trocar vogais por @\n\n");
- PtrTxt = fopen(NomeArq, "r+");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- Pos = 0;
- L = toupper(fgetc(PtrTxt));
- while(!feof(PtrTxt))
- {
- fflush(PtrTxt);
- Pos++;
- if(L == 'A' || L == 'E' || L == 'I' || L == 'O' || L == 'U')
- {
- if(Pos == 1)
- fseek(PtrTxt, 0, 0);
- else
- fseek(PtrTxt, Pos - 1, 0);
- fputc('@', PtrTxt);
- }
- fseek(PtrTxt, Pos, 0);
- L = toupper(fgetc(PtrTxt));
- }
- fclose(PtrTxt);
- printf("\n\nProcesso concluido\n\n");
- }
- getch();
- }
- void NotepadClone(void)
- {
- int TL, i;
- char Texto[50][200], Aux[200], NomeArq[100];
- FILE *PtrTxt;
- system("cls");
- printf("Escrever no arquivo\n\n");
- printf("Digite o nome do arquivo:\n");
- fflush(stdin);
- gets(NomeArq);
- TL = 0;
- printf("Digite o conteudo da linha %d:\n", TL + 1);
- fflush(stdin);
- gets(Aux);
- while(TL < 50 && strcmp(Aux, "FIM") != 0)
- {
- strcpy(Texto[TL++], Aux);
- printf("\nDigite o conteudo da linha %d:\n", TL + 1);
- fflush(stdin);
- gets(Aux);
- }
- PtrTxt = fopen(NomeArq, "a");
- for(i = 0; i < TL; i++)
- {
- fputs(Texto[i], PtrTxt);
- fputc(10, PtrTxt);
- }
- fclose(PtrTxt);
- printf("\n\nGravacao realizada\n\n");
- getch();
- }
- void CriptografaMesmoArquivo(char NomeArq[100])
- {
- int Chave, Pos;
- char L, M;
- FILE *PtrTxt;
- system("cls");
- PtrTxt = fopen(NomeArq, "r+");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- do
- {
- printf("Chave de criptografia (1-26):\n");
- scanf("%d", &Chave);
- }while(Chave < 1 || Chave > 26);
- L = toupper(fgetc(PtrTxt));
- Pos = 0;
- while(!feof(PtrTxt))
- {
- fflush(PtrTxt);
- fseek(PtrTxt, Pos, 0);
- Pos++;
- if(L == ' ')
- M = '#';
- else if(L >= 65 && L <= 90)
- {
- M = L + Chave;
- if(M > 90)
- M = 64 + (M - 90);
- }
- else
- fseek(PtrTxt, Pos - 2, 0);
- fputc(M, PtrTxt);
- fseek(PtrTxt, Pos, 0);
- L = toupper(fgetc(PtrTxt));
- }
- fclose(PtrTxt);
- printf("\n\nProcesso Concluido\n\n");
- }
- getch();
- }
- void SubstituiFgets(char NomeArq[100], char Palavra[100], char Sub[100])
- {
- int i, TL;
- char Linha[100], StrAux[100];
- FILE *PtrTxt;
- system("cls");
- printf("Substituir palavras\n\n");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n\n", NomeArq);
- else
- {
- FILE *PtrAux = fopen("Temp.txt", "a");
- strcpy(StrAux, "\0");
- TL = 0;
- fgets(Linha, 100, PtrTxt);
- while(!feof(PtrTxt))
- {
- for(i = 0; i < strlen(Linha); i++)
- {
- if(toupper(Linha[i]) >= 65 && toupper(Linha[i]) <= 90)
- StrAux[TL++] = Linha[i];
- else
- {
- StrAux[TL] = '\0';
- if(stricmp(StrAux, Palavra) == 0)
- {
- strcpy(StrAux, Sub);
- TL = strlen(Sub);
- StrAux[TL++] = Linha[i];
- StrAux[TL] = '\0';
- }
- else
- {
- StrAux[TL++] = Linha[i];
- StrAux[TL] = '\0';
- }
- fputs(StrAux, PtrAux);
- strcpy(StrAux, "\0");
- TL = 0;
- }
- }
- fgets(Linha, 100, PtrTxt);
- }
- fputs("\n", PtrAux);
- fclose(PtrTxt);
- fclose(PtrAux);
- remove(NomeArq);
- rename("Temp.txt", NomeArq);
- printf("\n\nProcesso concluido\n\n");
- }
- getch();
- }
Add Comment
Please, Sign In to add comment