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.

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.