请问在51单片机中,如何通过C语言将浮点数转变为字符串呢? 30

因为向液晶输出要字符串... 因为向液晶输出要字符串 展开
 我来答
carefreeswin
2006-04-15 · TA获得超过179个赞
知道答主
回答量:67
采纳率:0%
帮助的人:59.9万
展开全部
sprintf, swprintf
Write formatted data to a string.

Routine Required Header
sprintf <stdio.h>
swprintf <stdio.h>

int sprintf( char *buffer, const char *format [, argument] ... );
int swprintf( wchar_t *buffer, const wchar_t *format [, argument] ... );
Parameters
buffer
Storage location for output
format
Format-control string
argument
Optional arguments
Libraries
All versions of the C run-time libraries.

Return Value
sprintf returns the number of bytes stored in buffer, not counting the terminating null character. swprintf returns the number of wide characters stored in buffer, not counting the terminating null wide character.

Remarks
The sprintf function formats and stores a series of characters and values in buffer. Each argument (if any) is converted and output according to the corresponding format specification in format. The format consists of ordinary characters and has the same form and function as the format argument for printf. A null character is appended after the last character written. If copying occurs between strings that overlap, the behavior is undefined.

swprintf is a wide-character version of sprintf; the pointer arguments to swprintf are wide-character strings. Detection of encoding errors in swprintf may differ from that in sprintf. swprintf and fwprintf behave identically except that swprintf writes output to a string rather than to a destination of type FILE.

Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE Defined
_stprintf swprintf

Example
/* SPRINTF.C: This program uses sprintf to format various
* data and place them in the string named buffer.
*/

#include <stdio.h>
void main( void )
{
char buffer[200], s[] = “computer”, c = ‘l’;
int i = 35, j;
float fp = 1.7320534f;

/* Format and print various data: */
j = sprintf( buffer, “\tString: %s\n”, s );
j += sprintf( buffer + j, “\tCharacter: %c\n”, c );
j += sprintf( buffer + j, “\tInteger: %d\n”, i );
j += sprintf( buffer + j, “\tReal: %f\n”, fp );

printf( “Output:\n%s\ncharacter count = %d\n”, buffer, j );
}

Output
Output:
String: computer
Character: l
Integer: 35
Real: 1.732053

character count = 71

参考资料: MSDN

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式