C printf()和scanf()的*修饰符
关于printf()
和scanf()
有个神奇的*
修饰符,他和通配其实没什么关系,而且printf
和scanf
的作用不一样,所以一个个来看吧。
#include <stdio.h>
int main(void)
{
unsigned width, precision;
int number = 256;
double weight = 242.5;
printf("What field width?\n");
scanf("%d", &width);
printf("The number is: %*d: \n", width, number);
printf("Now enter a width and a precision: \n");
scanf("%d %d", &width, &precision);
printf("Weight = %*.*f\n", width, precision, weight);
return 0;
}