snprintf 不适用于双精度。得到'?
snprintf doesn't work with double. Getting '?'
我正在寻找在 c 中将双精度值显示为字符串的方法。但是使用 snprintf 我得到的是问号而不是价值。我的代码:
char temp[50];
double c = 19.15928891;
snprintf(temp, 8,"%lf", c);
putstring(-2, temp); //send characters to rs232 (here getting only '?')
谁能告诉我另一种显示双精度字符串的方法?
已编辑,希望现在问题没问题:)
尝试 %f
而不是 %lf
。根据您的图书馆的年龄,%lf
与 %f
相同或错误(因此首先使用 %f
)。
还要注意 19.159289
(printf
的结果)需要 10 个字节来存储,而不是 8 个。
我正在寻找在 c 中将双精度值显示为字符串的方法。但是使用 snprintf 我得到的是问号而不是价值。我的代码:
char temp[50];
double c = 19.15928891;
snprintf(temp, 8,"%lf", c);
putstring(-2, temp); //send characters to rs232 (here getting only '?')
谁能告诉我另一种显示双精度字符串的方法?
已编辑,希望现在问题没问题:)
尝试 %f
而不是 %lf
。根据您的图书馆的年龄,%lf
与 %f
相同或错误(因此首先使用 %f
)。
还要注意 19.159289
(printf
的结果)需要 10 个字节来存储,而不是 8 个。