Console Application

This is a discussion on Console Application within the C++ Programming forums, part of the General Programming Boards category; So I'm writing a console application for dos and such, and I wrote this while loop such that I keep ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    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.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    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

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You could also clear the screen and then re output the prompt.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Given that he's showed no code, it's hard to tell...
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    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.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    It's all the more difficult without knowing which OS and Compiler is being used.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    may i say them(sorry bout that), Microsoft Visual .Net and WINDOWS XP PRO ...yada

  11. #11
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Try system("CLS").
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    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
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple snmp console application.
    By csteinsv in forum C++ Programming
    Replies: 0
    Last Post: 06-01-2009, 05:03 PM
  2. Subject:How to create a C# console application?
    By Adock in forum C# Programming
    Replies: 5
    Last Post: 09-03-2008, 05:58 PM
  3. Adding interface to Win32 console application
    By motiz in forum Windows Programming
    Replies: 5
    Last Post: 01-03-2008, 02:17 AM
  4. Running a console application
    By maxorator in forum C++ Programming
    Replies: 4
    Last Post: 10-03-2005, 04:23 AM
  5. Console Application
    By Mont_Blanc in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2004, 03:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21