关于scanf()
来源:互联网 发布:python datetime 分钟 编辑:程序博客网 时间:2024/05/20 16:01
scanf函数原型:
int scanf(const char *format…..);
从标准输入流stdin中按格式format将数据写到参数表中;若操作成功,返回写到参数表中的参数个数,否则返回EOF
%d 会自动过滤掉空格和回车,
%c会读入所有的字符,包括空格和回车
#include <stdio.h>
int main() {
char command; int x1, x2;
while ( int c = scanf( "%c%d%d\n", &command, &x1, &x2 ) ) { //read no more than 3 items in current line
switch ( c ) { //#items scanf() reads
case EOF : return 0; //end of input stream
case 0 : printf("impossible\n"); break; //blank lines are ignored by scanf()
case 1 : printf("single: %c\n", command); break;
case 2 : printf("double: %c %d \n", command, x1); break;
case 3 : printf("triple: %c %d %d\n", command, x1, x2); break;
default : printf("impossible\n"); break;
}
}
}
以上代码表示读入的文本中,最多读入3个输入;若不足3个输入,继续输入的空格和回车都将视为等待下一个数字的读入,若下一个是除空格和回车以外的字符,则认为一次输入结束,开始下一次输入。
- 关于scanf
- 关于scanf
- 关于scanf()
- 关于scanf
- 关于scanf()
- 关于scanf
- 关于scanf()函数
- 关于scanf的用法
- 关于scanf()的学习
- 关于scanf()函数
- 关于scanf()函数
- 关于scanf返回值
- 关于scanf()
- 关于scanf与指针
- 关于scanf的疑问
- 关于getchar()、scanf()、gets()
- 关于scanf/printf
- 关于scanf函数
- VMnet0意外删除,找回方法!
- Lowest Common Ancestor of a Binary Search Tree
- 百度api申请key
- A20 linux(dragonboard)同时使用Parallel CSI Camera及UVC
- zookeeper学习总结
- 关于scanf()
- 内核启动流程分析之Makefile
- 获取网络连接字符串-模板代码
- Android测试教程3--用Robotium来生自动生成操作
- 【算法】希尔排序
- PSCarouselView
- [Windows] 删除收藏夹里的位置
- Linux下ifconfig命令只出现lo
- 归并树 划分树 模板