Limit input charachter

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 11
Reputation: akira_shinizaki is an unknown quantity at this point 
Solved Threads: 0
akira_shinizaki akira_shinizaki is offline Offline
Newbie Poster

Limit input charachter

 
0
  #1
Nov 22nd, 2008
How we can limit input data ? For example we only want the user to input 4 characters, user only can write up to 4 characters. Thank you fot your help.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Limit input charachter

 
0
  #2
Nov 22nd, 2008
By reading each character one at a time. If you get to 5 and that character is not '\n', print an error and clear out the rest of the characters from the input buffer.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Limit input charachter

 
0
  #3
Nov 22nd, 2008
You can probably accept input as a string and indicate error if length is longer than four.

Bottom line, you can't prevent user from not goofing up. All you can do is try to handle it if it is a goof.
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC