Menu

force an auto enter after x amt char entered?

kip2847
2007-10-17
2012-09-26
  • kip2847

    kip2847 - 2007-10-17

    what i want to do is after a certain amount of characters is entered the program automatically forces a "enter key" stroke or Null character.

    i.e.

    int x;
    cin>> x; // after the third digit is entered program automatically press enter not allowing
    // that fourth digit.

    i already know i can use a control loop that repeats until the user enters in a proper condition, but i dont want to go that route.

    thanx

     
    • Anonymous

      Anonymous - 2007-10-18

      You cannot do it using iostream or stdio calls becauase input is line oriented, none of the input function return until enter is pressed so you have no control.

      If you need to use standard library functions the best you can do is validate the input after it is entered - in this case testing for x < 1000, or accepting input as a string, and thaking only the characters you need before converting then to an integer.

      To do exactly what you asked you need to use the Win32 Console API: http://msdn2.microsoft.com/en-us/library/ms682073.aspx

      Automatically terminating input after three digits is not very user friendly - users typically want teh opportunity to visually verify and edit there input before committing it.

      Finally - its not a "dos program" it is a Win32 Console Mode program - there is (thankfully) a whole world of a difference.

       
    • kip2847

      kip2847 - 2007-10-17

      Sorry more info is
      am using dev c++ 4.9.9.2
      windows xp
      dos program

       
    • Osito

      Osito - 2007-10-17

      I'm just curious, if you know you can use a loop, why don't you want to go that route?

       
    • kip2847

      kip2847 - 2007-10-17

      because i want to limit the user

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.