Basic knowledge-scanf

简介: Basic knowledge-scanf

scanf 输入成功的返回值是 输入的个数 eg:scanf(“%d",&a),返回1

scanf在输入缓冲区读取失败会返回EOF(end of file)

读取成功之前无视空格和回车

一次输入的结束标志是回车

scanf会自动在输入缓冲区读取数据(如果有数据的话,没有的话就会等待用户输入)

下图中,我用键盘一次性输入了10 20 30,随即按下回车,表明一次输入完成,但程序直接输出了10 20 30.逻辑是,我把 10空格20空格30回车 输入到了输入缓冲区,10 被提取给了a,随即遇到空格,scanf结束。接着是第二个scanf,检查输入缓冲区是否有数据,此时存在20 30,提取20给b,随即遇到空格,结束这次的scanf。第三次和前两次一样(第三次是怎么样提取结束的,?)

c35729dd6c01494aa5c1076474ae1e42.png

相关文章
|
算法 数据挖掘 开发者
basic concept| 学习笔记
快速学习 basic concept。
basic concept| 学习笔记
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
209 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
|
机器学习/深度学习 测试技术 Python
PAT (Basic Level) Practice (中文)第1002题
PAT (Basic Level) Practice (中文)第1002题
115 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
100 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
109 0
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
103 0
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
185 0
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
108 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
124 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
140 0