0

How would I make it so that a string only accepts a statement that is between a certain amount of characters? An example would be a sentence between 4 and 8 characters long. Would it be strlen, and if so how?

0

Assuming this is about c:

You could indeed use strlen() to check the length of the input string. In that case, you should put the input statement somewhere within a loop which only exits when the length of the string happens to be within the chosen boundaries.

Choose whichever loop feels more natural to you:

  • For instance, you might choose a while loop. But in that case you should initialize the input string before the loop, which might feel unnatural to you.
  • You might use an infinite loop, and break out of it as soon as you like the input. Again, that might feel unnatural to you.
  • ...

And to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .