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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.
Sorry more info is
am using dev c++ 4.9.9.2
windows xp
dos program
I'm just curious, if you know you can use a loop, why don't you want to go that route?
because i want to limit the user