Reputation: 171
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
Reputation: 6846
Even without c++11 and regex, validating the input should be fairly straightforward:
strlen
of both arrays should be >= 1.strlen
of both arrays should be <= array size-1.Upvotes: 3