当我在下面的代码中使用sscanf()时,由于某种原因,它将整行放在第一个字符串中,并且我没有发现任何问题。从消息()的输出是走出像PatchVersion=1.1.1.5 = °?¦§-
sscanf()无法正确识别格式
文件看起来是这样的(除了每个是一个新行,不知道为什么它显示了一个在计算器上)
PatchVersion=1.1.1.5
ProductName=tf
appID=440
代码:
bool ParseSteamFile()
{
FileHandle_t file;
file = filesystem->Open("steam.inf", "r", "MOD");
if(file)
{
int size = filesystem->Size(file);
char *line = new char[size + 1];
while(!filesystem->EndOfFile(file))
{
char *subLine = filesystem->ReadLine(line, size, file);
if(strstr(subLine, "PatchVersion"))
{
char *name = new char[32];
char *value = new char[32];
sscanf(subLine, "%s=%s", name, value);
Msg("%s = %s\n", name, value);
}
else if(strstr(subLine, "ProductName"))
{
char *name = new char[32];
char *value = new char[32];
sscanf(subLine, "%s=%s", name, value);
Msg("%s = %s\n", name, value);
}
}
return true;
}
else
{
Msg("Failed to find the Steam Information File (steam.inf)\n");
filesystem->Close(file);
return false;
}
filesystem->Close(file);
return false;
}
以供将来参考,*请*发表最小的代码示例,即再现错误最小编译代码(你大约4行可以做这个例子)。这使得其他人更容易阅读,并且您可能会在过程中发现错误。 – 2010-11-05 13:02:05