Page 1 of 1

HTML to TBHTML Converter

Posted: Thu Feb 27, 2014 6:18 pm
by ppk-center
Здравствуйте. Вот пишу свой HTML конвертатор. Никаких синтаксических ошибок в коде нет. Но вместо результата выдаётся тире. Не подскажите в чём дело? (Дебаг ни к чему не приводит)

Code: Select all

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

int main()
{
char * str;
str=(char *)malloc(sizeof(char)*9999);
{
char *str_replace(char *orig, char *rep, char *str)
{
static char buffer[4096];
char *p;
if(! (p = strstr(str, orig)))
return str;
strncpy(buffer, str, p - str);
buffer[p - str] = '\0';
sprintf(buffer + (p - str), "%s%s", rep, p + strlen(orig));
return buffer;
}

printf("Enter html text: ");
scanf("%d", str);
// for correct work
str = str_replace("<script>", "<!--", str);
str = str_replace("</script>", "-->", str);
str = str_replace("<style>", "<!--", str);
str = str_replace("</style>", "-->", str);
str = str_replace("<binary>", "<!--", str);
str = str_replace("</binary>", "-->", str);
// tags changing
str = str_replace("<caption", "<center", str);
str = str_replace("/caption>", "/center>", str);
str = str_replace("<address", "<i", str);
str = str_replace("/address>", "/i>", str);
str = str_replace("<footer", "<hr><footer", str);
str = str_replace("/header>", "/header><hr>", str);
str = str_replace("<basefont", "<font", str);
str = str_replace("/basefont>", "/font>", str);
str = str_replace("<details", "<a href=$1>Show all datails</a> <condition show_if=1", str);
str = str_replace("/details>", "/condition>", str);
str = str_replace("<plaintext", "<pre", str);
str = str_replace("/plaintext>", "/pre>", str);
str = str_replace("<wbr", "<span", str);
str = str_replace("<xmp", "<pre", str);
str = str_replace("/xmp>", "/pre>", str);
// span inline style converter
str = str_replace("font-weight: bold;", "><b><", str);
str = str_replace("font-style: italic;", "><i><", str);
str = str_replace("text-decoration: underline;", "><u><", str);
str = str_replace("text-decoration: line-through;", "><s><", str);
str = str_replace("font-weight:bold;", "><b><", str);
str = str_replace("font-style:italic;", "><i><", str);
str = str_replace("text-decoration:underline;", "><u><", str);
str = str_replace("text-decoration:line-through;", "><s><", str);
str = str_replace("/span>", "/b></i></u></s>", str);
printf("%s", str);
}
free(str);
}


Re: HTML to TBHTML Converter

Posted: Thu Feb 27, 2014 6:45 pm
by 0CodErr
Возможно, из-за

Code: Select all

scanf("%d", str);
Ты же число читаешь.

Re: HTML to TBHTML Converter

Posted: Fri Feb 28, 2014 4:23 pm
by ppk-center
Спасибо, просто я знаю только PHP а к Си никак не могу привыкнуть.

Re: HTML to TBHTML Converter

Posted: Sun Mar 16, 2014 4:49 pm
by ppk-center
HTML to TBHTML Converter
Ну вот наконец-то я доделал эту программу! Она конвертирует HTML код в понятный текстовому браузеру.
Spoiler:Программа функционирует следующим образом: в неё необходимо ввести HTML код. Затем она выдаёт его в преобразованном виде.
Кстати, во многих браузерах HTML-код до отображения сначала преобразуется. Я предлагаю, чтобы перед отображением HTML-кода текстовый браузер пропускал это через это фильтр!