- C 標準庫
- C 庫 - 首頁
- C 庫 - <assert.h>
- C 庫 - <complex.h>
- C 庫 - <ctype.h>
- C 庫 - <errno.h>
- C 庫 - <fenv.h>
- C 庫 - <float.h>
- C 庫 - <inttypes.h>
- C 庫 - <iso646.h>
- C 庫 - <limits.h>
- C 庫 - <locale.h>
- C 庫 - <math.h>
- C 庫 - <setjmp.h>
- C 庫 - <signal.h>
- C 庫 - <stdalign.h>
- C 庫 - <stdarg.h>
- C 庫 - <stdbool.h>
- C 庫 - <stddef.h>
- C 庫 - <stdio.h>
- C 庫 - <stdlib.h>
- C 庫 - <string.h>
- C 庫 - <tgmath.h>
- C 庫 - <time.h>
- C 庫 - <wctype.h>
- C 標準庫資源
- C 庫 - 快速指南
- C 庫 - 有用資源
- C 庫 - 討論
- C 程式設計資源
- C 程式設計 - 教程
- C - 有用資源
C 庫 - towlower() 函式
C 的wctype 庫 towlower() 函式用於將給定的寬字元轉換為小寫字元(如果可能)。
此函式可用於不區分大小寫的比較、文字規範化或使用者輸入處理。
語法
以下是 towlower() 函式的 C 庫語法:
wint_t towlower( wint_t wc );
引數
此函式接受單個引數:
-
wc − 一個型別為 'wint_t' 的寬字元,將被轉換為小寫。
返回值
如果寬字元已更改為小寫字元,則此函式返回小寫字元;否則返回未更改的字元(如果它已經是小寫字元或不是字母字元)。
示例 1
以下是一個基本的 C 示例,演示了 towlower() 函式的使用。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
int main() {
// wide character
wchar_t wc = L'G';
// convert to lowercase
wint_t lower_wc = towlower(wc);
wprintf(L"The lowercase equivalent of %lc is %lc\n", wc, lower_wc);
return 0;
}
輸出
以下是輸出:
The lowercase equivalent of G is g
示例 2
我們建立一個 C 程式來比較字串是否相等。 使用 towlower() 轉換為小寫後進行比較。如果兩個字串相等,則表示不區分大小寫,否則區分大小寫。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
#include <string.h>
int main() {
wchar_t str1[] = L"Hello World";
wchar_t str2[] = L"hello world";
// flag value
int equal = 1;
// comepare both string after compare
for (size_t i = 0; i < wcslen(str1); ++i) {
if (towlower(str1[i]) != towlower(str2[i])) {
// strings are not equal
equal = 0;
break;
}
}
if (equal) {
wprintf(L"The strings are equal (case insensitive).\n");
} else {
wprintf(L"The strings are not equal.\n");
}
return 0;
}
輸出
以下是輸出:
The strings are equal (case insensitive).
示例 3
下面的示例將寬字元規範化為小寫字元。
#include <wchar.h>
#include <wctype.h>
#include <stdio.h>
int main() {
// Wide string
wchar_t text[] = L"Normalize THIS Tutorialspoint!";
size_t length = wcslen(text);
wprintf(L"Original text: %ls\n", text);
// Normalize the text to lowercase
for (size_t i = 0; i < length; i++) {
text[i] = towlower(text[i]);
}
wprintf(L"Normalized text: %ls\n", text);
return 0;
}
輸出
以下是輸出:
Original text: Normalize THIS Tutorialspoint! Normalized text: normalize this tutorialspoint!
c_library_wctype_h.htm
廣告