如果我有一个“MessageLine”来显示消息和输入提示输入:
像这样:
MessageLine: Type 123!
Input:
然后,输入错误的内容,会显示“错误!”在 MessageLine
上:
MessageLine: Wrong!
Input: somewronginput
然后,用户不知道下一步该做什么,我希望在 3 秒后再次显示第一条消息,但光标仍位于输入提示处,这意味着 MessageLine 会更改其消息而不影响输入提示。
我的“MessageLine”或任何解决方案是否碰巧有一个独立的序列?
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
void msgline(int msg_var){
char *msg[]={
"Type Numbers \"123\"",
"Wrong! Try Again",
"Correct! Press Any Key to Exit..."
};
gotoxy(25,1);
clreol();
printf("Message: %s",msg[msg_var]);// Message Box
}
void main()
{
char inp[256]={0},
answr[]="123";
clrscr();
do{
msgline(0);
printf("\n\nInput: ");
clreol();
scanf("%s",&inp);
if(!strcmp(inp,answr));
else{
memset(inp,0,sizeof(inp));
msgline(1); // Wrong input
delay(3000);
/* delay function also delays the loop
and the cursor is at the message's end of line */
}
}
while(strcmp(inp,answr));
msgline(2); // Correct input
getch();
}
最佳答案
此级别的控制不是输出流的标准 C 定义的一部分。
根据您的平台,您也许可以使用GNU ncurses例如。
关于c - 在不中断 C 中的输入提示的情况下在不同位置打印消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19658018/