①%c紧密相连
#include<studio.h>
main()
{
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
printf("a=%c,b=%c,c=%c",a,b,c);
}
输入:123 输出:a=1,b=2,c=3
输入:1 23 输出:a=1,b=,c=2
空格作为字符输出
~
②%c之间有空格
#include<studio.h>
main()
{
char a,b,c;
scanf("%c %c %c",&a,&b,&c);
printf("a=%c,b=%c,c=%c",a,b,c);
}
输入:123 输出:a=1,b=2,c=3
输入:1 23 输出:a=1,b=2,c=3
输入:1 2 3 输出:a=1,b=2,c=3
空格作为间隔符,不输出
~
③%c前有数字
#include<studio.h>
main()
{
char a,b,c;
scanf("%2c %2c %2c",&a,&b,&c);
printf("a=%c,b=%c,c=%c",a,b,c);
}
输入:123 输出:没有结果
输入:1 23 输出:没有结果
输入:1 2 3 输出:a=1,b=2,c=3
算上空格,总宽度为6,才有结果。
必须按指定宽度输入,
取指定宽度第一个字符输入。
最新评论