printf()的*修饰符
#include <stdio.h>
int main(void)
{
unsigned width, precision;
int number = 256;
double weight = 242.5;
printf("Enter a field width:\n");
scanf_s("%d", &width);
printf("Tne number is :%*d:\n", width, number); //width提供字段宽度
printf("Now enter a width and a precision:\n");
scanf_s("%d %d", &width, &precision);
printf("Weight = %*.*f\n", width, precision, weight); //width和precision提供格式化信息
printf("Done!\n");
return 0;
}
scanf()的*修饰符
把*放在%和转换字符之间,scanf()会跳过相应的输入项。
在程序需要读取文件中特定列的内容时很有用。
#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;
}