#include<stdio.h>
int main()
{
/*
%0不足补零2宽度为二d:
%f:guding
%2宽度为二.2精确到小数点后两位f:
%-靠左对其2宽度为二:
%5宽度为五4输出字符数为四s:
*/
printf("%d,%5d,%-5d,%05d,%+d\n",-12,-12,-12,-12,12);
printf("%f,%-15f,%15f,%8.2f,%08.2f\n",123.0,123.0,123.0,123.0,0,123.0);
char* str ="hello";
printf("%s,%10s,%-10s,%6.3s\n",str,str,str,str);
int w =10;
printf("%c %*c \n",'A',w,'A');//*:stand for varible in printf
int x,y;
scanf("%3d %4d",&x,&y);//123456789
printf("x=%d,y=%d\n",x,y);//x=123,y=4567
scanf("%*d %d",&x);//*:stand for abandon in scanf
printf("x=%d\n",x);//123 456 x=456
char a1[20],a2[20];
scanf("%*[^\n]");
scanf("%*c");
scanf("%[a-z]%[^a-z]",a1,a2);//er32g3fr
printf("%s %s\n",a1,a2);//er 32
scanf("%[^\n]%*c"); //读取一行数据,如果不是换行符号,就一直读,%*c抛弃换行符号
return 0;
}
格式控制符
最新推荐文章于 2022-02-05 15:09:23 发布