0

I can't figure out what function I can use to check what does a string contain as instructed that we can use a function in the docs.cs50 assignment page. Neither do I understand why this code doesn't work ?

bool check_flag(char *str)
{
if (strlen(str) == 3)
{
    if (str[0] == '-' &&  (str[1] == 'a' || str[1] == 'b' || str[1] == 'r' 
|| str[1] == 's') && str[2] == '\0')
    {
        return true;
    }
    else
    {
        return false;
    }
}
else
{
    return false;
}

}

0

it seems that if the condition is never met, make sure the length of the string is actually 3 Note that the function strlen counts the number of characters to the end of string character, but this last character is not counted

1

You must log in to answer this question.

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