Advertisement
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>
- #define LIM 101
- 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 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[100], char Letra)
- {
- FILE *PtrTxt;
- char LetraArq;
- int flag;
- 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) != toupper(Letra))
- flag = 1;
- while(!feof(PtrTxt))
- {
- if(LetraArq == ' ')
- {
- LetraArq = fgetc(PtrTxt);
- if(toupper(LetraArq) != toupper(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 QuebraArquivo(char NomeArq[100])
- {
- int TL, i;
- char linha[100], aux[100];
- FILE *PtrTxt;
- system("cls");
- PtrTxt = fopen(NomeArq, "r");
- if(PtrTxt == NULL)
- printf("Arquivo %s inexistente\n", NomeArq);
- else
- {
- FILE *PtrAux = fopen("Novo.txt", "w");
- TL = 0;
- strcpy(aux, "\0");
- fgets(linha, 100, PtrTxt);
- while(!feof(PtrTxt))
- {
- for(i = 0; linha[i] != '\0'; i++)
- if(toupper(linha[i]) >= 65 && toupper(linha[i]) <= 90)
- aux[TL++] = linha[i];
- else if(linha[i] == ' ' || linha[i] == 10)
- {
- aux[TL] = '\0';
- fputs(aux, PtrAux);
- fputs("\n", PtrAux);
- TL = 0; strcpy(aux, "\0");
- }
- fgets(linha, 100, PtrTxt);
- }
- fclose(PtrTxt);
- fclose(PtrAux);
- printf("\n\nProcesso concluido\n\n");
- getch();
- LeArquivo("Novo.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement