-
Console Application
So I'm writing a console application for dos and such, and I wrote this while loop such that I keep asking for the correct input, you know validating correct inputs, well all i wanted to was when the user gave me the incorrect input they would reenter the data. The problem is I only want to prompt the user once, and I don't won't to scroll down another line, is it possible to delete the input that was entried? My only solution was to use for loops some escape commands, reposted the same prompts, and wa-lah! any suggestions, if i can't do it go ahead and say so, I've been told i can't do several things b4.
-
Once the user has entered a newline, you have no way to scroll up a line without using escape sequences or some other platform-dependent method.
You could use getch() or another non-standard unbuffered input function to read your input instead.
Is there any reason that you don't want the screen to scroll?
-
eh, no reason besides looks.
getch() what does that do? which header is it from? sorry that I ask I'm pretty new to programming
-
Note the word non-standard. Your compiler might not have it; if you're using Dev-C++ or an old DOS compiler, you might. If you do, it's usually in <conio.h>. http://faq.cprogramming.com/cgi-bin/...&id=1043284392
To get getch() to do what you want, check for an enter (which is '\r' with getch()), sort of like this: http://board.theprogrammingsite.com/viewtopic.php?t=143
-
You could also clear the screen and then re output the prompt.
-
To do so: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
If there's other stuff on the screen, it might be difficult to repaint the screen:
Code:
Enter your name: dwks
Enter your type: wizard
Enter your starting level: one
-
Given that he's showed no code, it's hard to tell...
-
But when i ask for an input with cin, and press enter, won't my screen automatically scroll down another line or so?, So I can't exactly retrace, or can I? i just don't know is it possible. But as for manutd, are you suggesting using the ms-dos command cls, clear screen. I''ve exactly learned how to use dos functions within my code. How would I go about doing that, I've been interested in doing that also.
-
It's all the more difficult without knowing which OS and Compiler is being used.
-
may i say them(sorry bout that), Microsoft Visual .Net and WINDOWS XP PRO ...yada
-
-
It's in the FAQ I posted.
system() is a function in <stdlib.h>; it executes a system command, which for Windows is a DOS command.
You might also be able to set the cursor position on the screen, again with a non-standard function: http://faq.cprogramming.com/cgi-bin/...&id=1043284392