Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C sprintf()未正确对齐_C_Xc8 - Fatal编程技术网

C sprintf()未正确对齐

C sprintf()未正确对齐,c,xc8,C,Xc8,我正在使用MPLAB 5.25和XC8(2.10)为PIC18F42K47编译一个程序 我想打印右对齐到缓冲区,但输出总是左对齐。 这是我的密码: uint8_t Str_1[10] = {0}; uint8_t Str_2[10] = {0}; uint8_t Str_3[10] = {0}; sprintf(Str_1, "%3.2f", 12.345); // -> "12.35" sprintf(Str_2, "%04.2f", 2.345); // -> "

我正在使用MPLAB 5.25和XC8(2.10)为PIC18F42K47编译一个程序

我想打印右对齐到缓冲区,但输出总是左对齐。 这是我的密码:

uint8_t Str_1[10] = {0};
uint8_t Str_2[10] = {0};
uint8_t Str_3[10] = {0};

sprintf(Str_1, "%3.2f", 12.345);    // -> "12.35" 
sprintf(Str_2, "%04.2f", 2.345);    // -> "2.35"  
sprintf(Str_3, "% 3.1f", -123.4);   // -> "-123.4"

格式说明符在小数点左侧有一个宽度参数。此数字描述的是最小字符数,而不是小数点前的字符数

sprintf(Str_1, "%8.3f", 12.345);    // -> "  12.345"

格式说明符在小数点左侧有一个宽度参数。此数字描述的是最小字符数,而不是小数点前的字符数

sprintf(Str_1, "%8.3f", 12.345);    // -> "  12.345"

尝试使用更宽的格式说明符,例如
%6.2f
12.35是5个字符宽。你的领域是3。等等。尝试使用更宽的格式说明符,例如
%6.2f
12.35是5个字符宽。你的领域是3。等