gpt4 book ai didi

android NDK fopen 路径有空格失败

转载 作者:行者123 更新时间:2023-11-30 19:32:20 44 4
gpt4 key购买 nike

我正在尝试将 libxml2 移植到 android。当我使用带空格的文件路径时(例如路径=“/storage/emulated/0/sdcard/New XML.xml”),打开xml文件失败。但是如果我使用不带空格的路径(例如“/storage/emulated/0/sdcard/NewXML” .xml”。解析文件成功。请帮我解决这个问题。

下面是示例代码:

#include <stdio.h>
#include <libxml/xmlreader.h>

static void
processNode(xmlTextReaderPtr reader) {
const xmlChar *name, *value;

name = xmlTextReaderConstName(reader);
if (name == NULL)
name = BAD_CAST "--";

value = xmlTextReaderConstValue(reader);

printf("%d %d %s %d %d",
xmlTextReaderDepth(reader),
xmlTextReaderNodeType(reader),
name,
xmlTextReaderIsEmptyElement(reader),
xmlTextReaderHasValue(reader));
if (value == NULL)
printf("\n");
else {
if (xmlStrlen(value) > 40)
printf(" %.40s...\n", value);
else
printf(" %s\n", value);
}
}

static void streamFile(const char *filename) {
xmlTextReaderPtr reader;
int ret;

reader = xmlReaderForFile(filename, NULL, 0);
if (reader != NULL) {
ret = xmlTextReaderRead(reader);
while (ret == 1) {
processNode(reader);
ret = xmlTextReaderRead(reader);
}
xmlFreeTextReader(reader);
if (ret != 0) {
fprintf(stderr, "%s : failed to parse\n", filename);
}
} else {
fprintf(stderr, "Unable to open %s\n", filename);
}
}

int main() {
const char path[64] = "/storage/emulated/0/sdcard/New XML.xml"

streamFile(path);

xmlCleanupParser();
xmlMemoryDump();

return(0);
}

最佳答案

对您的空间进行编码...

xmlReaderForFile filename: a file or URL

关于android NDK fopen 路径有空格失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47204516/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com