#include <stdio.h>
int main(void)
{
unsigned width, precision;
int number = 256;
double weight = 242.5;
printf("输入一个字段宽度\n");
scanf_s("%d", &width);
printf("the number is:%*d:\n", width, number);
printf("Now enter a width and a precision;\n");
scanf_s("%d %d", &width, &precision);
printf("Weight = %*.*f\n",width, precision, weight);
return 0;
}
状态不是特别好,看了半天,大概看懂了。
可以使用*,*的格式代替n,n来指定字段宽度。暂时没get到其高明之处,不还是要在后引号的逗号后面指定吗?
#include <stdio.h>
int main(void)
{
int n;
printf("Please enter three integers:\n");
scanf("%*d %*d %d", &n);
printf("The last integer was %d\n", n);
return 0;
}
不知道如何评价scanf_s里的*,感觉有点憨。或许和别的函数配合使用有用吧。