c语言中大小写字符转换

c语言中大小写字符转换。

1、

#include <stdio.h>
#include <ctype.h>

void upper(char x[])
{
    int i = 0;
    while(x[i])
    {
        x[i] = toupper(x[i]);
        i++;
    }
}

void lower(char x[])
{
    int i = 0;
    while(x[i])
    {
        x[i] = tolower(x[i]);
        i++;
    }
}

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    upper(str);
    printf("upper result: %s\n", str);
    
    lower(str);
    printf("lower result: %s\n", str);
    
    return 0;
}

 

#include <stdio.h>
#include <ctype.h>

void upp(char x[])
{
    int i = 0;
    while(x[i])
    {
        x[i] = toupper(x[i]);
        i++;
    }
}

void low(char x[])
{
    int i = 0;
    while(x[i])
    {
        x[i] = tolower(x[i]);
        i++;
    }
}

int main(void)
{
    char str[128];
    printf("str: "); scanf("%s", str);
    
    upp(str);
    printf("upp: %s\n", str);
    
    low(str);
    printf("low: %s\n", str);
    
    return 0;
}

 

posted @ 2021-05-27 17:02  小鲨鱼2018  阅读(1835)  评论(0编辑  收藏  举报