完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
各位大侠您们好
有个新问题请教,我要是用 vsprintf显示字符,为什么%d,%s都可以,而%f一直都是0.000000? 这个问题可是奇怪了,还有大侠指教下啊?谢谢 #include #include #include #include #include void Uart_Printf(char *pTransBuf,char *fmt,...) { u8 i; va_list ap; va_start(ap,fmt); vsprintf(pTransBuf,fmt,ap); va_end(ap); } 数据填入pTransBuf缓冲区,使用%f,固定就填0.000000,晕死 |
|
相关推荐
2个回答
|
|
extern _ARMABI int fprintf(FILE * __restrict /*stream*/,
const char * __restrict /*format*/, ...) __attribute__((__nonnull__(1,2))); /* * writes output to the stream pointed to by stream, under control of the * string pointed to by format that specifies how subsequent arguments are * converted for output. If there are insufficient arguments for the format, * the behaviour is undefined. If the format is exhausted while arguments * remain, the excess arguments are evaluated but otherwise ignored. The * fprintf function returns when the end of the format string is reached. * The format shall be a multibyte character sequence, beginning and ending * in its initial shift state. The format is composed of zero or more * directives: ordinary multibyte characters (not %), which are copied * unchanged to the output stream; and conversion specifiers, each of which * results in fetching zero or more subsequent arguments. Each conversion * specification is introduced by the character %. For a description of the * available conversion specifiers refer to section 4.9.6.1 in the ANSI * draft mentioned at the start of this file or to any modern textbook on C. * The minimum value for the maximum number of characters producable by any * single conversion is at least 509. * Returns: the number of characters transmitted, or a negative value if an * output error occurred. */ #pragma __printf_args extern _ARMABI int _fprintf(FILE * __restrict /*stream*/, const char * __restrict /*format*/, ...) __attribute__((__nonnull__(1,2))); /* * is equivalent to fprintf, but does not support floating-point formats. * You can use instead of fprintf to improve code size. * Returns: as fprintf. */ #pragma __printf_args extern _ARMABI int printf(const char * __restrict /*format*/, ...) __attribute__((__nonnull__(1))); /* * is equivalent to fprintf with the argument stdout interposed before the * arguments to printf. * Returns: the number of characters transmitted, or a negative value if an * output error occurred. */ #pragma __printf_args extern _ARMABI int _printf(const char * __restrict /*format*/, ...) __attribute__((__nonnull__(1))); /* * is equivalent to printf, but does not support floating-point formats. * You can use instead of printf to improve code size. * Returns: as printf. */ #pragma __printf_args extern _ARMABI int sprintf(char * __restrict /*s*/, const char * __restrict /*format*/, ...) __attribute__((__nonnull__(1,2))); /* * is equivalent to fprintf, except that the argument s specifies an array * into which the generated output is to be written, rather than to a * stream. A null character is written at the end of the characters written; * it is not counted as part of the returned sum. * Returns: the number of characters written to the array, not counting the * terminating null character. */ extern _ARMABI int vsprintf(char * __restrict /*s*/, const char * __restrict /*format*/, __va_list /*arg*/) __attribute__((__nonnull__(1,2))); /* * is equivalent to sprintf, with the variable argument list replaced by * arg, which has been initialised by the va_start macro (and possibly * subsequent va_arg calls). The vsprintf function does not invoke the * va_end function. * Returns: the number of characters written in the array, not counting the * terminating null character. */--------------------------------------------- 看stdio.h头文件里面,我颜色标明的部分,已经说明不支持float了。 |
|
|
|
我的767用printf,还是sprintf都可以打印浮点的。
头文件里面有个编译开关: #pragma __printf_args 控制着具体的函数实现方式,你用CUBEMX生成工程看看,可能CUBE默认的编译开关支持浮点。 sprintf用起来真不省心,很有可能不是你想象的结果。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2201 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
2027 浏览 3 评论
4633 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2171 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2705 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 05:05 , Processed in 0.720077 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号