Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool input_is_valid(char str[WANTED_STRING_LENGTH + 1]) {
- if(string_length(str) > WANTED_STRING_LENGTH) {
- return false;
- }
- for(int i = 0; str[i] != '\0'; i++) {
- if(str[i] < 'a' || str[i] > 'z') {
- return false;
- }
- }
- return true;
- }
- int main() {
- char str[WANTED_STRING_LENGTH + 1];
- do{
- cout << "Enter a string up to " << WANTED_STRING_LENGTH << " characters long"
- << " and composed only of small letters from the english alphabet:" << endl;
- cin.getline(str, WANTED_STRING_LENGTH + 2);
- } while(!input_is_valid(str));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment