C-字符串大小写转换


void func(char *str, int flag);

int main()
{
    char buff[100];
    printf("从键盘上输入字符串:");
    scanf("%s", buff);
    printf("源字符串%s\n", buff);
    func(buff, 0);
    printf("大写转小写:%s \n", buff);
    func(buff, 1);
    printf("小写转大写%s \n", buff);
    return 0;
}

void func(char *str, int flag)
{
    int data;
    while (*str != '\0')
    {
        if (flag)
        {
            if (*str >= 'a' && *str <= 'z')
            {
                *str = *str - 32;
            }
        }
        else
        {
            if (*str >= 'A' && *str <= 'Z')
            {
                *str = *str + 32;
            }
        }
        str++;
    }
}

你可能感兴趣的:(C-字符串大小写转换)