c - 在不中断 C 中的输入提示的情况下在不同位置打印消息

标签 c

如果我有一个“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/

相关文章:

c - 将最高分保存在文件中

c++ - 如何从 C++ 调用 Matlab 函数

c - 表达式 ( arr[i+1] - arr[i] ) 如何产生与索引差相同的十进制数?

c - 读取数据并用C重写后文件大小更改

c - 如何按顺序打印多个文件中的行?

c - 创建许多线程条件变量和互斥量是否合理/明智?

c - 为什么尝试扫描名称会产生段错误?

c++ - if 宏中的语句不起作用

c - 在网络环境中从 Brother TD-4100N 打印机检索打印机状态

c - 受限3人体模拟无法正常工作