sprintf Conversion Specifiers

Publisher:BlissfulMomentsLatest update time:2015-09-09 Source: eefocusKeywords:sprintf Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Conversion specifiers: %a(%A) floating point number, hexadecimal number and p-(P-) notation (C99) %c character %d signed decimal integer %f floating point number (including float and doulbe) %e(%E) floating point number exponential output [e-(E-) notation] %g(%G) floating point number does not display meaningless zero "0" %i signed decimal integer (same as %d) %u unsigned decimal integer %o octal integer eg 0123 %x(%X) hexadecimal integer 0f(0F) eg 0x1234 %p pointer %s string %% "%" 2. Left alignment of sign: "-" eg "%-20s" Right alignment: "+" eg "%+20s" Space: If the sign is positive, a space is displayed, if it is negative, "-" is displayed eg "% 6.2f" #: No effect on c, s, d, u; for o, add a prefix o when output; for x, add a prefix 0x when output; for e, g, f, only give a decimal point when the result has a decimal. 3. Format string (format) 〔Sign〕〔Minimum output width〕〔. Precision〕〔Length〕Type "%-md": Left alignment, if m is less than the actual value, output according to the actual value. "%m.ns": output m digits, take n digits from the left of the string, fill with spaces on the left, when n>m or m is omitted, m=n eg "%7.2s" input CHINA output "CH" "%m.nf": output floating point number, m is the width, n is the number of digits to the right of the decimal point eg "%3.1f" input 3852.99 output 3853.0 Length: h is a short integer, l is a long integer
Keywords:sprintf Reference address:sprintf Conversion Specifiers

Previous article:Problem of char int conversion in C language
Next article:Summary of some knowledge about arrays, strings, etc. in C language

Recommended ReadingLatest update time:2024-11-24 20:54

Solution to the error of sprintf converting characters in 51 MCU
sprintf is a function in the C language library that converts data types. There is a situation where In 51 MCU, define unsigned char temp; Then I want to use the serial port to print out temp in decimal form, so I convert it like this: sprintf((char*)tem, "%d", temp); that is, first convert temp into the decimal chara
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号