【发布时间】:2020-10-29 04:14:43
【问题描述】:
是否可以提示用户再次输入一个字符并让新字符替换原来的字符?当我尝试这个时,它不允许我第二次输入字符。
#include <stdio.h>
int main(){
char x;
printf("enter value: ");
scanf("%c", &x);
printf("enter value: ");
scanf("%c", &x);
}
【问题讨论】:
-
不允许,因为你可能放了空格,尝试
scanf(" %c", &x)在%c之前注意空格.. -
成功了,谢谢。
-
是的,这是可能的。确保清除之前输入可能留下的缓冲区。
标签: c