在c中将指定的内容放入缓冲区

在c中将指定的内容放入缓冲区,c,C,我正在用c从http服务器下载一个jsp文件。但是我得到了文件的内容,如图所示 <HTML> <BODY> Hello, user </BODY> </HTML> 你好,用户 进入缓冲区。现在我只想将“Hello,user”捕获到我的缓冲区中。有人能帮我找到C中的代码吗?基本上,您希望扫描缓冲区并忽略介于之间的所有内容: char*get_text(char*dst,char*src){ int html=0; char ch; while(

我正在用c从http服务器下载一个jsp文件。但是我得到了文件的内容,如图所示

<HTML>
<BODY>
Hello, user
</BODY>
</HTML>

你好,用户

进入缓冲区。现在我只想将“Hello,user”捕获到我的缓冲区中。有人能帮我找到C中的代码吗?

基本上,您希望扫描缓冲区并忽略介于
之间的所有内容:

char*get_text(char*dst,char*src){
int html=0;
char ch;
while(ch=*src++){
如果(ch=''){

html=(ch='您可以尝试剥离html,但如果标记外有更多内容,这可能无法正常工作(需要更具体的筛选,例如检查周围的标记名)

未经测试但应有效:

char *html = ...; // html being a pointer to the document's contents
int ip = 0; // the input position
int op = 0; // the ouput position
int in_tag = 0; // are we inside a html tag?
char c; // current character
while(c = html[ip++])
{
    if(c == '<')
        in_tag = 1;
    else if(c == '>')
        in_tag = 0;
    else if(c == '\n' || c == '\r') // strip line breaks
        ;
    else if(!in_tag)
        html[op++] = c;
}
html[op] = '\0';
char*html=…;//html是指向文档内容的指针
int ip=0;//输入位置
int op=0;//输出位置
int in_tag=0;//我们是否在html标记中?
char c;//当前字符
而(c=html[ip++])
{
如果(c='')
in_tag=0;
else if(c=='\n'| | c=='\r')//带线中断
;
如果(!in_标记)
html[op++]=c;
}
html[op]='\0';

使用libexpat。这是一个用C编写的面向流的xml解析器。您可以注册BODY标记的处理程序并读取内容


看看这个问题

发布一些代码可以帮助人们更容易、更有效地回答这个问题。你说“文件内容如图所示”在问题中,但我没有看到任何内容。由于剥离了HTML标记,它被隐藏。修复了该问题。@Ozair我希望将HTML标记元素化,并希望将Hello,user存储到缓冲区值中。。。
char *html = ...; // html being a pointer to the document's contents
int ip = 0; // the input position
int op = 0; // the ouput position
int in_tag = 0; // are we inside a html tag?
char c; // current character
while(c = html[ip++])
{
    if(c == '<')
        in_tag = 1;
    else if(c == '>')
        in_tag = 0;
    else if(c == '\n' || c == '\r') // strip line breaks
        ;
    else if(!in_tag)
        html[op++] = c;
}
html[op] = '\0';