我正在学习 C 编程。%c我写了一个奇怪的循环,但在我使用in时不起作用scanf()。
这是代码:
#include<stdio.h>
void main()
{
char another='y';
int num;
while ( another =='y')
{
printf("Enter a number:\t");
scanf("%d", &num);
printf("Sqare of %d is : %d", num, num * num);
printf("\nWant to enter another number? y/n");
scanf("%c", &another);
}
}
但是如果我%s在这段代码中使用,例如scanf("%s", &another);,那么它工作正常。
为什么会这样?任何想法?