各位大侠您们好 有个新问题请教,我要是用 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,晕死 |
GUI_TOUCH_Exec(); 就出问题了,这个是怎么回事情?
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了。
头文件里面有个编译开关:
#pragma __printf_args
控制着具体的函数实现方式,你用CUBEMX生成工程看看,可能CUBE默认的编译开关支持浮点。
sprintf用起来真不省心,很有可能不是你想象的结果。