你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32f203 使用vsprintf为什么不能显示浮点数?%f没用?

[复制链接]
xuyejin 提问时间:2017-6-30 09:35 /
各位大侠您们好

           有个新问题请教,我要是用 vsprintf显示字符,为什么%d,%s都可以,而%f一直都是0.000000?
这个问题可是奇怪了,还有大侠指教下啊?谢谢

#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>


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,晕死
收藏 评论9 发布时间:2017-6-30 09:35

举报

9个回答
xuyejin 回答时间:2017-6-30 09:36:16
使用的是是stm32f207,内部存储器
xuyejin 回答时间:2017-6-30 13:36:34
唉,没有人指教?怎么我尽碰到这种稀奇古怪的问题
xuyejin 回答时间:2017-7-3 11:22:48
顶一下,怎么没有人指教啊?
xuyejin 回答时间:2017-7-5 15:11:22
怎么没用回复?都没有碰到过么?
废鱼 回答时间:2017-7-5 16:21:32
楼主,没有碰到类似的问题,我一般使用sprintf,而且是直接调用。还是你编程的问题要多一些。ap这个值是什么类型?
xuyejin 回答时间:2017-7-28 11:42:44
我发现和stemwin 的 GUI_TOUCH_Exec(); 有关,不使用GUI_TOUCH_Exec(); 就没有问题,一循环调用
GUI_TOUCH_Exec(); 就出问题了,这个是怎么回事情?
xuyejin 回答时间:2017-7-28 11:48:20
就是使用sprintf也是一样,有指教的么?
kylongmu 回答时间:2017-7-28 15:10:57
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了。
kylongmu 回答时间:2017-7-28 15:32:13
我的767用printf,还是sprintf都可以打印浮点的。
头文件里面有个编译开关:
#pragma __printf_args
控制着具体的函数实现方式,你用CUBEMX生成工程看看,可能CUBE默认的编译开关支持浮点。
sprintf用起来真不省心,很有可能不是你想象的结果。

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版