Format conversion specifier scanf,printf format% daquan/formatted input/output

Source: Internet
Author: User

I believe that no matter the great God or the food birds, they recognize printf. And his family and his brother Sprintf,scanf,sscanf...$^&*.when you're gorgeous write down char c='C';p rintf ("char=%d", c), when everything is still so beautiful. But when you declare a char buf[2]; then sscanf ("30000","%d", BUF); it's not that fun. I thought 2 bytes was enough to fit the number within 32767, but it blew up the memory. The key here is the problem with the formatting. The most wanted is a complete list of available formats. Suffering every time can only find sporadic points not all, originally intended to do a complete collection, in the collection process found a full version of the conversion specifier printf ()/scanf () table One conversion description indicators output As a result of the PrintOut conversion description%a floating-point number, hexadecimal digits, and P-Counting Method (C99)%a floating-point number, hexadecimal digits, and P-Counting Method (C99)%C one character%d signed Decimal integer%e floating point number, E-method of counting%e floating point number, E-method of counting%F Floating-point number, decimal notation%g automatic selection according to different values%f or%e. %e format in exponent less than-4 or greater than or equal to precision when used%g automatic selection according to different values%f or%e. %e format in exponent less than-4 or greater than or equal to precision when used%I signed decimal integer (with%d same)%o unsigned octal integers%p pointer (means address)%s String%u unsigned decimal integer%x unsigned hexadecimal integer with hexadecimal digit 0f%x unsigned hexadecimal integer with hexadecimal digit 0F%%print a percent sign table two printf () modifier modifier meaning flag five flags (-, +, spaces, #, and 0) are described in Table III and can use the minimum value of 0 or more flags digit (s) field widths. If the field does not hold the number or string you want to print, the system uses a wider field. Example: "%4d ". Digit (s) accuracy. ForThe%e,%e, and%f conversions are the digits of the number that will be printed to the right of the decimal point. For%g and%g conversions, the maximum number of digits for a valid number. For the%s conversion, is the maximum number of characters that will be printed. For integer conversions, the minimum number of digits to be printed, or, if necessary, the number of digits to be reached with the leading zero. Use only "." Followed by a 0, so the%.F is the same as%.0f. Example: "%5.2f"Prints a floating-point number whose field width is 5 characters and has two digits after the decimal point. The H and integer conversion specifiers are used together to denote a shortintor unsigned. Short intThe type value. Example: "%hu ","%hx "and"%6The . 4hd "hh and integer conversion specifiers are used together to denote a signedCharor unsigned char type value. Example: "%hhu ","%HHX "and"%6The . 4hhd "J and integer conversion specifiers are used together to represent a intmax_t or uintmax_t value. Example: "%jd "and"%8jX "L is used with integer specifiers to denote a longintor unsigned.Long intThe type value. Example: "%ld "and"%8lu"ll is used with integer specifiers to denote a longLongint or unsignedLong Long intThe type value (C99). Example: "%lld "and"%The 8llu "L and floating-point conversion specifiers are used together to represent a long double value. Example: "%lf "and"%TenThe . 4Le "T and integer conversion specifier are used together to represent an example of a ptrdiff_t value (a type corresponding to the difference between two pointers) (C99):"%td "and"%The 12ti "Z and integer conversion specifiers are used together to represent a size_t value (the type that sizeof returns) (C99). Example: "%zd "and"%12zx "table three printf () the Mark modifier meaning-The item is left-aligned, that is, the item is printed to the left of the field at the beginning. Example: "%-20s "+if the signed value is positive, a symbol with a plus sign is displayed, or a sign with a minus sign if it is negative. Example: "%+6.2f"(space) if the signed value is positive, the display is preceded by a leading space (but not the symbol) and, if negative, with a minus sign. The + flag will overwrite the space mark. Example: "%6.2f"#使用转换说明的可选形式. If the%o format, starting at 0, if%x and%x format, starting at 0x or 0X, for all floating-point forms, #保证了即使不限任何数字, also prints a decimal character. For%g and%g formats, it prevents trailing 0 from being deleted. Example: "% #o", "% #8.0f"and"%+#Ten. 3E "0for all number formats, fill the field width with leading zeros instead of spaces. If it appears-Flag or specify the precision (for integers) to ignore the flag. Example: "%010d" and "%08.3fThe conversion specifier conversion specifier meaning of scanf () in table four Ansic%C interprets the input as a character%D interpret the input as a signed decimal integer%e,%f,%g,%a interprets the input as a floating-point number (%A is C99 standard)%e,%f,%g,%a interprets the input as a floating-point number (%A is C99 standard)%I interpret the input as a signed decimal integer%o interpret the input as a signed octal number%P interprets the input as a pointer (address)%s interprets the input as a string; The input begins with a non-whitespace character and contains all the characters that know the next whitespace character%u interprets the input as an unsigned decimal integer%x,%x interpret the input as a signed hexadecimal integer table five scanf () conversion modifier modifier meaning*lag assignment. Example: "%*d "Digit (s) maximum field width; Stop reading entries when the maximum field width is reached or when the first blank character is encountered (whichever occurs first). Example: "%10s "HH reads integers as signedCharor unsignedChar。 Example: "%HHD" "%Hhu "ll read integers as long long or unsignedLong Long(C99). Example: "%lld" "%llu "h,l or L"%HD "and" HI "indicate that the value will be stored in a short int. "%ho ""%hx "and"%hu "indicate that the value will be stored in a unsigned ShortInt. "%ld "and"%Li "indicates that the value will be stored in a long. "%lo "%LX" and "%Lu "indicates that the value will be stored in a unsigned long. "%le "%LF" and "%LG "indicates that the value is stored as a double type. Use L (not L) with E, F, and G to indicate that the value is stored in a long double type.                  Without these modifiers, D, I, O, and x indicate the int type, while E, F, and G indicate the float type. Table attached to a special specifier conversion descriptor meaning%I64 with U,d and so on, you can input and output 64-bit integers. The MSVC platform is valid.%i64u,%I64d. Note Capitalize the last summary, a byte of%C,%HHU,%HHD, etc., two bytes with%hu,%hd, four bytes with%d,%u 8 bytes of%lld,%llu and so on. Try not to use%I64d is not compatible with this format. Adhering to the spirit of open source, the above content is welcome to correct, add!respect for the original, respect for intellectual property, starting from me. This article refers to: http://www.cnblogs.com/zxpgo/archive/2012/08/10/2632169.html

Format conversion specifier scanf,printf format% daquan/formatted input/output (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.