#include <stdbool.h>// check string to verify it consists// of only lower-case alpha charactersbool is_lowercase(const char *string) { char *p = string; do { if ((*p < 'a' || *p > 'z') && *p != '\0') { // INSERT MISSING CODE } } while (*p++ != '\0'); return true;}
Question
#include <stdbool.h>// check string to verify it consists// of only lower-case alpha charactersbool is_lowercase(const char *string) { char *p = string; do { if ((*p < 'a' || *p > 'z') && *p != '\0') { // INSERT MISSING CODE } } while (*p++ != '\0'); return true;}
Solution
It seems like you want to complete the function is_lowercase which checks if a string consists only of lower-case alpha characters. The missing code should return false if a non-lowercase character is found. Here is the completed function:
#include <stdbool.h>
bool is_lowercase(const char *string) {
char *p = string;
do {
if ((*p < 'a' || *p > 'z') && *p != '\0') {
return false;
}
} while (*p++ != '\0');
return true;
}
In this function, we iterate over each character in the string. If we find a character that is not a lowercase letter (i.e., it is either less than 'a' or greater than 'z'), we immediately return false. If we reach the end of the string without finding any non-lowercase characters, we return true.
Similar Questions
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.