0、自己实际遇到的坑
Mac下如果用标准键盘,使用scanf输入时不能用小键盘上的回车,否则系统不能很好的识别。
1、scanf函数的基本使用
1: // 定义一个变量,用来保存用户输入的整数
2: int number;
3:
4: // scanf函数只接受变量的地址
5: // scanf函数是一个阻塞式的函数,等待用户输入
6: // 用户输入完毕后,就会将用户输入的值赋值给number变量
7: // 函数调用完毕
8: scanf("%d", &number);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2、scanf的其他用法和注意点
1: /* 1.输入字符
2: char myc;
3:
4: scanf("%c", &myc);
5:
6: printf("输入的字符是%c\n", myc);
7: */
8:
9: /* 2.一次性输入多个数值,并且以某些符号隔开
10: int num1, num2;
11:
12: scanf("%d#%d", &num1, &num2);
13:
14: printf("num1=%d, num2=%d\n", num1, num2);
15: */
16:
17: /*
18: 3.如果scanf参数中以空格隔开,实际输入可以以空格、tab、回车作为分隔符
19: int num1, num2;
20: scanf("%d %d", &num1, &num2);
21: printf("num1=%d, num2=%d\n", num1, num2);
22: */
23:
24: /*
25: 4.scanf中不能写\n
26: int a;
27: scanf("%d\n", &a); // 错误写法
28: printf("a的值是%d\n", a);
29: */
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }