*}
codea teams

Proper Case



Convert a string to proper case.

char *ProperCase(char *string)
{
    if (NULL == string)
        return NULL;

    char *s;
    int count = 0;

    for (s = string; *s; ++s, count++)
    {
        if (count == 0)
        {
            if (*s >= 'a' && *s <= 'z')
                *s = *s - 32;
        }
        else if (*s >= 'A' && *s <= 'Z' && *(s - 1) != ' ')
        {
            *s = *s + 32;
        }
        else if (*s >= 'a' && *s <= 'z' && *(s - 1) == ' ')
        {
            *s = *s - 32;
        }
    }

    return string;
}