关于 "%*d" 一类的用法总结
2009-08-31 10:59
363 查看
在C语言的输入输出流中,有时会出现 "%*d" 等的用法,上网搜了一下,总结如下:
输入时
"%*d" 等表示“虚度
”,即不读,例如:
double v1,v2;
scanf(" %lf %*d %lf %*d",&v1,&v2);
执行时必须有是个输入,如
11 22 33 44
但事实上只有第一个和第三个是有效输入,则v1=11 v2=33 输入域22和44被跳过了。
输出时
"%*d" 中的 "*" 表示占位符
,例如:
float f = 3.14159;
printf( "%*.*f", 10, 2, f);
输出时按出现顺序用10和2分别替换两个*,它等同于:printf("%10.2f", f);
又如
printf(
"%*d"
, 2,1);
则结果是 “ 1“
,注意,数字1前面有一位空格,因为指定的输出格式是2位的。
最后注意
的格式是
printf("%#o",a);
中,#o表示以八进制数表示a(为0ZZ的形式);同样, #x表示以十六进制数表示(为0xZZ或0XZZ)。
输入时
"%*d" 等表示“虚度
”,即不读,例如:
double v1,v2;
scanf(" %lf %*d %lf %*d",&v1,&v2);
执行时必须有是个输入,如
11 22 33 44
但事实上只有第一个和第三个是有效输入,则v1=11 v2=33 输入域22和44被跳过了。
输出时
"%*d" 中的 "*" 表示占位符
,例如:
float f = 3.14159;
printf( "%*.*f", 10, 2, f);
输出时按出现顺序用10和2分别替换两个*,它等同于:printf("%10.2f", f);
又如
printf(
"%*d"
, 2,1);
则结果是 “ 1“
,注意,数字1前面有一位空格,因为指定的输出格式是2位的。
最后注意
的格式是
printf("%#o",a);
中,#o表示以八进制数表示a(为0ZZ的形式);同样, #x表示以十六进制数表示(为0xZZ或0XZZ)。
相关文章推荐
- 总结C++中三种关于"new"的使用方法
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- 关于js iframe 中"window(parent)(top).location.href"的用法
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结 (转载)
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- asp.net中关于<% %>、<%= %>的用法——个人总结
- 关于jstl EL用法的注意点(java.lang.NumberFormatException: For input string: "userName")
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- 关于make: *** No rule to make target""问题总结
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- 达内第15天培训知识总结,关于大数字的精确浮点运算以及linkList<>用法
- 2015关于第十一届"蓝狐网络杯"湖南省大学生计算机程序设计竞赛的总结
- asp.net中关于&lt;% %&gt;、&lt;%= %&gt;的用法总结 .
- 关于正则表达式 g,m 参数的总结,为了回答“正则表达式(/[^0-9]/g,'')中的"/g"是什么意思?”
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结 今天在调试一个基础的Struts2框架小程