我想要一些关于如何读取“XML”之类文件的建议,以便程序仅读取/存储在满足某些要求的节点中观察到的元素。我正在考虑按以下方式使用两个 fget:
while (fgets(file_buffer,line_buffer,fp) != NULL)
{
if (p_str = (char*) strstr(file_buffer,"<element of interest opening")) )
{
//new fgets that starts at fp and runs only until the end of the node
{
//read and process
}
}
}
这有意义吗?或者有更聪明的方法吗?
其次(在我看来),我是否必须定义一个新的 FILE* (如 fr),在第二个 fgets 开始时将 fr 设置为 fp 或者我可以以某种方式滥用原始文件指针吗?
最佳答案
使用 XML 解析器,如 Xmllib2 http://xmlsoft.org/xml.html
关于c - 在 C 中使用 fgets 找到特定标记后读取文件的部分内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498905/