0

In the case that I have a "MessageLine" to display messages and an input prompt Input: Like this:

 MessageLine: Type 123!   
 Input: 

Then, typing a wrong input, would display "Wrong!" on the MessageLine:

MessageLine: Wrong!     
Input: somewronginput

Then, the user not knowing what to do next, I want the first message to be shown again after 3 seconds, BUT the cursor is still at the input prompt, means the MessageLine would change it's message without affecting the input prompt.

Could it happen to have an independent sequence for my "MessageLine" or whatever solution that would be?

#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();
}
4

1 回答 1

0

此级别的控制不是输出流的标准 C 定义的一部分。

例如,根据您的平台,您可能能够使用GNU ncurses

于 2013-10-29T12:20:37.633 回答