當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C語言 toupper()用法及代碼示例

toupper()函數用於將小寫字母轉換為大寫字母。即,如果傳遞的字符是小寫字母,則toupper()函數會將小寫字母轉換為大寫字母。它在ctype.h頭文件中定義。

用法:

int toupper(int ch);

參數:它接受一個參數:


  • ch:這表示要轉換為大寫字母的字符。

返回值:此函數返回對應於ch的大寫字符。

以下示例程序旨在說明C語言中的toupper()函數:

示例1:

// C program to demonstrate 
// example of toupper() function. 
#include <ctype.h> 
#include <stdio.h> 
  
int main() 
{ 
    char ch; 
  
    ch = 'g'; 
    printf("%c in uppercase is represented as  %c", 
           ch, toupper(ch)); 
  
    return 0; 
}
輸出:
g in uppercase is represented as  G

示例2:

// C program to demonstrate 
// example of toupper() function. 
#include <ctype.h> 
#include <stdio.h> 
  
int main() 
{ 
    int j = 0; 
    char str[] = "geekforgeeks\n"; 
    char ch; 
  
    while (str[j]) { 
        ch = str[j]; 
        putchar(toupper(ch)); 
        j++; 
    } 
  
    return 0; 
}
輸出:
GEEKFORGEEKS


相關用法


注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 toupper() function in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。