2013-10-29 17 views
0

中斷輸入提示在我有一個「MessageLine」顯示消息和輸入提示Input: 這樣的案例:打印在不同的位置的消息,而無需使用C

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(); 
} 
+2

看看[ncurses](http://invisible-island.net/ncurses/ncurses-intro.html#introduction) – Kninnug

回答

0

該級別的控制不是輸出流的標準C定義的一部分。

根據您的平臺,您可能可以使用GNU ncurses爲例。