user3169700
user3169700

Reputation: 171

Can anyone think of a way I can error check this?

Here is the situation:

My program reads user-input into two char arrays (not allowed to use strings). The user inputs info like this: word;word

I do this with a do-while loop that has the condition that while the temp character that is being read into isn't ; to keep going cin << temp and assigning temp to the next char in the array. Then I load the second char array with a cin.get(variableName, 100, '\n').

I want to error check so that if the user doesn't enter words in the format word;word then they'll get an error message. Does anyone know what conditions I can set to check for this? I'm assuming they wouldn't enter word;word;word;word;word or anything but they might just enter word with no ;.

Upvotes: 0

Views: 79

Answers (1)

Carey Gregory
Carey Gregory

Reputation: 6846

Even without c++11 and regex, validating the input should be fairly straightforward:

  1. Count semicolons entered in both strings. There should be only one.
  2. strlen of both arrays should be >= 1.
  3. strlen of both arrays should be <= array size-1.
  4. If only certain types of chars are allowed (eg, no spaces or punctuation), scan both arrays for prohibited characters.

Upvotes: 3

Related Questions