Ir ao conteúdo

Problema com o codigo


djverty

Posts recomendados

Postado

eai pessoal beleza, então, estou fazendo este programa para eliminar tags de html e apresentar o texto puro na tela, mais nao funcionou...

Alguem pode tentar identificar o erro ou dar alguma dica para que posso fazer de outro forma...

Obrigado desde Ja!!!

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <strings.h>

main(){

FILE *fptr;

int i;

char string[128];

if ((fptr=fopen("teste.html","r"))==NULL){

printf ("Erro na abertura do Arquivo" );

system("pause");

exit(1);

}

fgets(string,128,fptr);

for (i=0; i<=128; i++){

if (string == '<'){

printf ("\n");

do{

i = i+1;

}while (string != '>');

}else {

printf ("%c", string);

}

}

system("pause");

fclose(fptr);

}

Postado

o fgets busca o conteúdo por linha.

Você vai precisar declarar um buffer intermediário:


char BUFFER[128];

É bom zerar o conteúdo dos arrays char:


bzero(BUFFER, sizeof(BUFFER));
bzero(string, sizeof(string));

E trocar a linha onde está o fgets, por esse trecho de código:


while (feof(fptr) == 0)
{
fgets( BUFFER, sizeof(BUFFER), fptr );
strcat( string, BUFFER );
}

Postado

Pra mim funcionou.

Segue o código completo para você comparar:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int main(void)
{
FILE *fptr;
int i;
char string[128];
char BUFFER[128];

bzero(string, sizeof(string));
bzero(BUFFER, sizeof(BUFFER));

if ( ( fptr=fopen("teste.html","r") ) == NULL )
{
printf ("Erro na abertura do Arquivo" );
system("pause");
exit(1);
}

while (feof(fptr) == 0)
{
fgets( BUFFER, sizeof(BUFFER), fptr );
strcat( string, BUFFER );
}

for ( i = 0; i <= sizeof(string); i++)
{

if (string[i] == '<')
{
printf ("\n");

do
{
i = i+1;

}
while (string[i] != '>');

}
else
{
printf ("%c", string[i]);
}
}

// system("pause");
fclose(fptr);
}

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

LANÇAMENTO!

eletronica2025-popup.jpg


CLIQUE AQUI E BAIXE AGORA MESMO!