toupper
來自 cppreference.com
在標頭檔案 <ctype.h> 中定義 |
||
int toupper( int ch ); |
||
根據當前安裝的 C 語言環境定義的字元轉換規則,將給定字元轉換為大寫。
在預設的 "C" 語言環境中,以下小寫字母 abcdefghijklmnopqrstuvwxyz
被替換為相應的大寫字母 ABCDEFGHIJKLMNOPQRSTUVWXYZ
。
目錄 |
[編輯] 引數
ch | - | 要轉換的字元。如果 ch 的值不能表示為 unsigned char 且不等於 EOF,則行為未定義。 |
[編輯] 返回值
ch 的大寫版本,如果當前 C 語言環境中沒有列出大寫版本,則返回未修改的 ch。
[編輯] 示例
執行此程式碼
#include <ctype.h> #include <limits.h> #include <locale.h> #include <stdio.h> int main(void) { // in the default locale: for (unsigned char l = 0, u; l != UCHAR_MAX; ++l) if ((u = toupper(l)) != l) printf("%c%c ", l, u); printf("\n\n"); unsigned char c = '\xb8'; // the character ž in ISO-8859-15 // but ¸ (cedilla) in ISO-8859-1 setlocale(LC_ALL, "en_US.iso88591"); printf("in iso8859-1, toupper('0x%x') gives 0x%x\n", c, toupper(c)); setlocale(LC_ALL, "en_US.iso885915"); printf("in iso8859-15, toupper('0x%x') gives 0x%x\n", c, toupper(c)); }
可能的輸出
aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ in iso8859-1, toupper('0xb8') gives 0xb8 in iso8859-15, toupper('0xb8') gives 0xb4
[編輯] 參考
- C23 標準 (ISO/IEC 9899:2024)
- 7.4.2.2 toupper 函式 (p: 待定)
- C17 標準 (ISO/IEC 9899:2018)
- 7.4.2.2 toupper 函式 (p: 147-148)
- C11 標準 (ISO/IEC 9899:2011)
- 7.4.2.2 toupper 函式 (p: 204)
- C99 標準 (ISO/IEC 9899:1999)
- 7.4.2.2 toupper 函式 (p: 185)
- C89/C90 標準 (ISO/IEC 9899:1990)
- 4.3.2.2 toupper 函式
[編輯] 另請參閱
將字元轉換為小寫 (函式) | |
(C95) |
將寬字元轉換為大寫 (函式) |
C++ 文件 關於 toupper
|