字符串大小写转换

时间:2022-12-05 21:05:04

头文件

#include <string.h> // for strlen
#include <ctype.h> // for toupper

字符串转大写

void WhStrUpper(char *pszString)
{
    if (pszString == NULL) {
        return;
    }

    size_t i = 0;
    for (i = 0; i < strlen(pszString); i++) {
        pszString[i] = toupper(pszString[i]);
    }
}

字符串转小写

void WhStrLower(char *pszString)
{
    if (pszString == NULL) {
        return;
    }

    size_t i = 0;
    for (i = 0; i < strlen(pszString); i++) {
        pszString[i] = tolower(pszString[i]);
    }
}