为什么c函数没有使用scanf函数进行第二次扫描



我被这个程序卡住了,帮帮我,这将是值得赞赏的。但是,一起扫描字符可能会奏效。我想知道为什么scanf在第二次没有问角色。

#include <stdio.h>
int main()
{
printf("--Mathematical operations on character to get other character--n");
char a, b;
printf("Enter the 1st character: n");
scanf("%c", &a);
printf("Enter the 2nd character: n");
scanf("%c", &b);//It's not scanning 2nd time, instead moving forward to printf function
printf("nThe ASCII equivalent for addition of %c and %c is %cn", a, b, (a + b));
printf("nThe ASCII equivalent for subtraction of %c and %c is %cn", a, b, (a - b));
printf("nThe ASCII equivalent for multiplication of %c and %c is %cn", a, b, (a * b));
printf("nThe ASCII equivalent for division of %c and %c is %cn", a, b, (a / b));
printf("nThe ASCII equivalent for modular division of %c and %c is %cn", a, b, (a % b));
return 0;
}

scanf("%c", &a);之后,输入流中的下一个字符是用户按回车键或回车键输入的n。然后scanf("%c", &b);读取该字符。

要告诉scanf跳过n,请使用scanf(" %c", &b);。空格告诉scanf读取所有空白字符,直到看到非空白字符为止。

相关内容

  • 没有找到相关文章

最新更新