我有一个文本文件,如下所示。
<HTML>
<BODY>
Hello, User
<BODY>
<HTML>
我需要一个C程序将Capture Hello,User转换为缓冲变量.. 谁能帮帮我吗.. 感谢
答案 0 :(得分:0)
这是一个非常简单的解决方案。
#include <stdio.h>
#include <string.h>
#define SIZE_OF_BUFFER 255
#define FILENAME "yourpage.html"
#define TRUE 1
#define FALSE 0
/* Read the contents of the (first) BODY tag into buffer */
int main(void)
{
int next_read = FALSE;
char buffer[SIZE_OF_BUFFER] = {'\0'};
FILE *htmlpage;
htmlpage = fopen(FILENAME, "r");
if(htmlpage == NULL)
{
printf("Couldn't locate file - exiting...");
return -1;
}
while(fscanf(htmlpage, " %[^\n]s", buffer) != EOF)
{
if(strncmp(buffer, "<BODY>", 6) == 0)
{
next_read = TRUE;
}
else if(next_read == TRUE)
{
break;
}
}
fclose(htmlpage);
if(next_read == TRUE)
{
/* print the contents of buffer */
printf("%s\n", buffer);
}
else
{
printf("No <BODY> tag found in file!\n");
}
return 0;
}