Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Remover caractere em um arquivo
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vellozo  
View profile   Translate to Translated (View Original)
 More options Dec 4 2009, 3:57 pm
From: Vellozo <vell...@gmail.com>
Date: Fri, 4 Dec 2009 12:57:46 -0800 (PST)
Local: Fri, Dec 4 2009 3:57 pm
Subject: Remover caractere em um arquivo
Como faço em C, para excluir caracteres tipo (. , ; ! ? ... etc) de
dentro de um arquivo texto comum?

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gianni  
View profile   Translate to Translated (View Original)
 More options Dec 4 2009, 6:43 pm
From: Gianni <nasus.maxi...@gmail.com>
Date: Fri, 4 Dec 2009 21:43:15 -0200
Local: Fri, Dec 4 2009 6:43 pm
Subject: Re: [ccppbrasil] Remover caractere em um arquivo
man fopen
man fread

Se não tiver um unix com manpages na mão... digita isso no google

ou, se vc não fizer muita questão;

system( "sed -i -e 's:!:g' arq.txt" );

mas aprender sed é mais dificíl que C!   ;-)

On Dec 4, 2009, at 6:57 PM, Vellozo wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marcio Gil  
View profile   Translate to Translated (View Original)
 More options Dec 4 2009, 6:46 pm
From: "Marcio Gil" <marciom...@bol.com.br>
Date: Fri, 4 Dec 2009 21:46:24 -0200
Local: Fri, Dec 4 2009 6:46 pm
Subject: RE: [ccppbrasil] Remover caractere em um arquivo

> -----Original Message-----
> From: Vellozo

> Como faço em C, para excluir caracteres tipo (. , ; ! ? ... etc)
de
> dentro de um arquivo texto comum?

Primeiramente, se não fosse em C você poderia utilizar o sed:

sed -i 's/[.,;!?]//g' arquivo.txt

Agora, respondendo sua pergunta, excluir ou adicionar qualquer coisa
em um arquivo texto geralmente significa:

I
- abrir o arquivo original;
- gravar o resultado do processamento em um arquivo temporário;
- remover ou renomear (com extensão .bak ou acrescentando ~) o
arquivo original;
- renomear o arquivo temporário para o nome e local do arquivo
original.

II
- renomear o arquivo original, abrindo-o em seguida;
- criar o novo arquivo com o nome e local do arquivo original;
- ler do backup, processar e gravar no novo arquivo;
- opcionalmente, excluir o backup se tudo ocorreu bem.

III (considerando que você só irá excluir caracteres e não inserir)
- abrir o arquivo original para leitura e gravação;
- trabalhar com dois ponteiros: a posição de leitura e a posição de
gravação;
- neste caso você teria que pular o tempo todo de uma posição para a
outra;
- não sei como, truncar o tamanho do arquivo.
(esta opção eu considero loucura)

Nota: a que eu acho mais segura é a opção I. Se alguma coisa der
errado no meio do processamento o arquivo original permanece
inalterado.

Se você optar pela opção I ou II você vai simplesmente trabalhar com
dois buffers, um de leitura e outro para gravação. Você percorre o
buffer de leitura com um contador, i por exemplo, e só joga no
buffer de gravação o que interessa.

Exemplo:

char buffer_in[512], buffer_out[512];
FILE *file_in, *file_out;
size_t i, j, n;

... /* aqui você renomeia e/ou abre os arquivos conforme a opção
escolhida */

while (!feof(buffer_in))
{
  n = fread( buffer_in, 1, 512, file_in );
  for (i = 0, j = 0; i < n; ++i)
  {
    if (!strchr( ".,;!?", buffer[i] ))
      buffer_out[j++] = buffer[i];
  }
  if (j > 0)
    fwrite( buffer_out, 1, j, file_out );

}

... /* aqui você fecha e/ou renomeia os arquivos conforme a opção
escolhida */

Marcio Gil.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vellozo  
View profile   Translate to Translated (View Original)
 More options Dec 5 2009, 7:30 am
From: Vellozo <vell...@gmail.com>
Date: Sat, 5 Dec 2009 04:30:40 -0800 (PST)
Local: Sat, Dec 5 2009 7:30 am
Subject: Re: Remover caractere em um arquivo
Tinha pensado nisso mesmo de outro arquivo, mas não sabia fazer isso.
Vou passar pro linux aqui e testar isso tudo aí....
Valeu mesmo... depois posto se consegui!

Hugo Vellozo


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vellozo  
View profile   Translate to Translated (View Original)
 More options Dec 5 2009, 8:23 am
From: Vellozo <vell...@gmail.com>
Date: Sat, 5 Dec 2009 05:23:52 -0800 (PST)
Local: Sat, Dec 5 2009 8:23 am
Subject: Re: Remover caractere em um arquivo
Não sei se estou certo mas tá dando uns paus aqui, pq vc está tentando
verificar, por exemplo ... !feof(buffer_in) mas buffer_in é um vetor
de string... isso pode? Ou é só pra arquivos?

abs

Hugo Vellozo


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Flavio Alberto Lopes Soares  
View profile   Translate to Translated (View Original)
 More options Dec 5 2009, 4:27 pm
From: Flavio Alberto Lopes Soares <flavio.thun...@gmail.com>
Date: Sat, 5 Dec 2009 19:27:50 -0200
Local: Sat, Dec 5 2009 4:27 pm
Subject: Re: [ccppbrasil] Re: Remover caractere em um arquivo

Onde se lê
while (!feof(buffer_in))
leia-se
while (!feof(file_in))

O parâmetro de feof() é o descritor de arquivo obtido em fopen() e não o
buffer lido.

Espero ter ajudado

Boa sorte
Sucesso
Flávio Alberto Lopes Soares

2009/12/5 Vellozo <vell...@gmail.com>


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marcio Gil  
View profile   Translate to Translated (View Original)
 More options Dec 6 2009, 7:05 am
From: "Marcio Gil" <marciom...@bol.com.br>
Date: Sun, 6 Dec 2009 10:05:58 -0200
Local: Sun, Dec 6 2009 7:05 am
Subject: RE: [ccppbrasil] Re: Remover caractere em um arquivo

Obrigado Flavio pela correção, foi erro de digitação mesmo :-)

E desculpe Vellozo pela falha ;-)

Qualquer outra dúvida manda o código que você já montou que a gente
te ajuda a corrigir.

Marcio Gil.

  _____  

From: Flavio Alberto Lopes Soares

Onde se lê
while (!feof(buffer_in))
leia-se
while (!feof(file_in))

O parâmetro de feof() é o descritor de arquivo obtido em fopen() e
não o buffer lido.

Espero ter ajudado

Boa sorte
Sucesso
Flávio Alberto Lopes Soares

2009/12/5 Vellozo <vell...@gmail.com>

Não sei se estou certo mas tá dando uns paus aqui, pq vc está
tentando
verificar, por exemplo ... !feof(buffer_in) mas buffer_in é um vetor
de string... isso pode? Ou é só pra arquivos?

abs

Hugo Vellozo


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marcio Gil  
View profile   Translate to Translated (View Original)
 More options Dec 6 2009, 7:11 am
From: "Marcio Gil" <marciom...@bol.com.br>
Date: Sun, 6 Dec 2009 10:11:00 -0200
Subject: Re: Remover caractere em um arquivo

A propósito, o trecho de código corrigido:

while (!feof(file_in))
{
  n = fread( buffer_in, 1, 512, file_in );
  for (i = 0, j = 0; i < n; ++i)
  {
    if (!strchr( ".,;!?", buffer_in[i] ))
      buffer_out[j++] = buffer_in[i];
  }
  if (j > 0)
    fwrite( buffer_out, 1, j, file_out );

}

  _____  

From: Marcio Gil

Obrigado Flavio pela correção, foi erro de digitação mesmo :-)

E desculpe Vellozo pela falha ;-)

Qualquer outra dúvida manda o código que você já montou que a gente
te ajuda a corrigir.

Marcio Gil.

  _____  

From: Flavio Alberto Lopes Soares

Onde se lê
while (!feof(buffer_in))
leia-se
while (!feof(file_in))

O parâmetro de feof() é o descritor de arquivo obtido em fopen() e
não o buffer lido.

Espero ter ajudado

Boa sorte
Sucesso
Flávio Alberto Lopes Soares

2009/12/5 Vellozo <vell...@gmail.com>

Não sei se estou certo mas tá dando uns paus aqui, pq vc está
tentando
verificar, por exemplo ... !feof(buffer_in) mas buffer_in é um vetor
de string... isso pode? Ou é só pra arquivos?

abs

Hugo Vellozo


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Flavio Alberto Lopes Soares  
View profile   Translate to Translated (View Original)
 More options Dec 7 2009, 7:11 am
From: Flavio Alberto Lopes Soares <flavio.thun...@gmail.com>
Date: Mon, 7 Dec 2009 10:11:04 -0200
Local: Mon, Dec 7 2009 7:11 am
Subject: Re: [ccppbrasil] Re: Remover caractere em um arquivo

A propósito,
    strtok (man 3 strtok) não te ajudaria não ?
E caso você esteja usando C++, as chamads de processamento de strings (
http://cplusplus.com/reference/string/string ) também não poderiam ajudar ?

Sucesso !
Flávio Alberto Lopes Soares

2009/12/6 Marcio Gil <marciom...@bol.com.br>


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vellozo  
View profile   Translate to Translated (View Original)
 More options Dec 7 2009, 12:50 pm
From: Vellozo <vell...@gmail.com>
Date: Mon, 7 Dec 2009 09:50:33 -0800 (PST)
Local: Mon, Dec 7 2009 12:50 pm
Subject: Re: Remover caractere em um arquivo
Exato Flávio... usei o strtok...
vou postar o código qndo estiver no meu note!

Valeu pela ajuda de todos!

Abs...

On 7 dez, 10:11, Flavio Alberto Lopes Soares


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vellozo  
View profile   Translate to Translated (View Original)
 More options Dec 9 2009, 6:48 am
From: Vellozo <vell...@gmail.com>
Date: Wed, 9 Dec 2009 03:48:39 -0800 (PST)
Local: Wed, Dec 9 2009 6:48 am
Subject: Re: Remover caractere em um arquivo
fiz assim! Pois alem de tirar a os caracteres "indesejaveis" tinha que
passa as palavras pra maiusculas.

        doc = fopen(arquivos[i],"r");

        while (fgets(aux, 100, doc)!=NULL)
        {
            *palavra = (char*)strtok(aux," .,!?;\n");

            while (*palavra != NULL)
            {
                tamanhoPalavra = strlen(*palavra);
                strcpy(aux, *palavra);

                for (j=0; j<tamanhoPalavra; j++) aux[j] = tolower(aux
[j]);

                strcpy(*palavra, aux);
                printf("Inserindo \"%s\"...\n",*palavra);

                *palavra = strtok(NULL, " .,!?;\n");
            }
        }

On Dec 7, 3:50 pm, Vellozo <vell...@gmail.com> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google