我需要用其他ascii值保留文本文件中某些double的精确二进制表示,因此我使用了中建议的“%a”
this
问题。
fprintf (pFile, "Scale: %a, %a, %a\n", scale.x, scale.y, scale.z);
但是,当我尝试用%la读入时,scanf返回0个已读项。
double x=0, y=0, z=0;
fgets(buf, sizeof buf, pFile);
int test = sscanf (buf, "Scale: %la, %la, %la\n", &x, &y, &z);
// test is zero!
布夫……”比例:0x1.fc70e3p-1、0x1.fc70e3p-1、0x1.fc70e3p-1\n“。。。
字符[1000]
为什么它看不懂?
应要求
Nate Eldredge
,这是我的MCVE版本:
#include <stdio.h>
int main(int argc, char *argv[])
{
double x=0, y=0, z=0;
const char* buf = "Scale: 0x1.fc70e3p-1, 0x1.fc70e3p-1, 0x1.fc70e3p-1\n";
int test = sscanf(buf, "Scale: %la , %la , %la", &x, &y, &z);
// test is zero!
}
第二点:我需要把源代码和数据文件发送给第三方,他有自己的编译器。因此保存格式必须相对独立于平台。