int ch = gechar(); //getchar接受标准输入
当接受到错误,或者到文本结尾的时候,会输出EOF,EOF是-1,所以,前面要用int类型
按下ctil+Z,就是EOF
注意:当按下字母和回车,这里输入的是两个字符,所以,会自动换行
putchar(ch); //输出ch
char password[20] = {0};
printf("请输入密码");
scanf("%s",password);
//getchar(); //这里getchar()读取了\n,防止
int ch = 0 ;
while ((ch = getchar()) != '\n') //或者将'\n'换成EOF
{
;
}
print("请确认密码");
int ret = getchar();
if('Y' == ret)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
6.调用随机数函数
产生随机数种子srand()
需要时间戳(时间戳是相对于计算机起始时间的秒)time(NULL)函数获得时间戳;//<time.h>
int a = rand(); //产生0~RAND_MAX(32767)之间的数 <stdlib.h>
srand((unsigned int)time(NULL));
int a = rand();
如果要想在0~100之间的数,直接取100的余数 +1