Scanf函数
输入
-#include<stdio.h>
int main(void)
{
int age;
printf("Please enter your age: \n");
scanf("%d",&age);//读取第一个非空数字,到下一个空字符截止
printf("your age is %d\n",age);
}
-#include<stdio.h>
int main(void)
{
char sts[10];
printf("Please enter your sts: \n");
scanf("%s",sts);//读取第一个非空字符,到下一个空字符截止
printf("your age is %s\n",sts);
}
-#include<stdio.h>
int main(void)
{
char st;
printf("Please enter your st: \n");
scanf("%c",&st);//只有单个字符特殊,空格回车等空字符被当作正常字符
printf("your st is %c\n",st);
}
-#include<stdio.h>
int main(void)
{
int age;
char t;
printf("Please enter your age and t: \n");
scanf("%d %c",&age,&t);//确定了输入格式,两个输入中间为空格符
printf("your age is %d,%c\n",age,t);
}
-#include<stdio.h>
int main(void)
{
char st;
printf("Please enter your st: \n");
scanf(" %c",&st);//读取位置从第一个非空白字符开始
printf("your age is %c\n",st);
}
返回值
返回成功输入项目数
未读到返回0
浙公网安备 33010602011771号