F. *_* Ni 1 c user-input scanf
我试图从用户那里获取两个字符。但我得到一个错误。让我解释一下。
当我编译并运行此代码时:
#include <stdio.h>
int main(){
char ch1,ch2;
printf("Enter the first character: ");
scanf("%c",&ch1);
printf("Enter the second character: ");
scanf("%c",&ch2);
printf("The characters are %c and %c",ch1,ch2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
Enter the first character: 1
Enter the second character: The characters are 1 and
Run Code Online (Sandbox Code Playgroud)
我无法输入第二个字符。但是当我这样做时:
Enter the first character: 12
Enter the second character: The characters are 1 and 2
Run Code Online (Sandbox Code Playgroud)
如果我输入 12,程序将 '1' 作为第一个字符,将 '2' 作为第二个字符。
如何在不一起输入两个字符的情况下从用户那里获取两个字符。
| 归档时间: |
|
| 查看次数: |
3285 次 |
| 最近记录: |