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


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


C編程中的isupper()函數檢查給定字符是否為大寫。 isupper()函數在ctype.h頭文件中定義。
用法:

int isupper ( int x );

例子:

Input:A
Output:Entered character is uppercase character
Input:a
Output:Entered character is not uppercase character
Input:1
Output:Entered character is not uppercase character
// C program to demonstrate 
// isupper() function 
#include <ctype.h> 
#include <stdio.h> 
int main() 
{ 
    char ch = 'A'; 
  
    // checking uppercase 
    if (isupper(ch)) 
        printf("\nEntered character is uppercase character"); 
    else
        printf("\nEntered character is not uppercase character"); 
}

輸出:


Entered character is uppercase character

應用:C編程語言中的isupper()函數用於查找給定句子中存在的大寫字母總數。
例:

Input:GEEKSFORGEEKS
Output:Number of upper case present in the sentence is:13
Input:GeeksFORGeeks
Output:Number of upper case present in the sentence is:5
Input:geeksforgeeks
Output:Number of upper case present in the sentence is:0
// C program to demonstrate 
// isupper() function 
  
#include <ctype.h> 
#include <stdio.h> 
  
// called function 
int ttl_upper(int i, int counter) 
{ 
    char ch; 
    char a[50] = "GeeksForGeeks"; 
    ch = a[0]; 
  
    // counting of upper case 
    while (ch != '\0') { 
        ch = a[i]; 
        if (isupper(ch)) 
            counter++; 
  
        i++; 
    } 
  
    // returning total number of upper case present in sentence 
    return (counter); 
} 
int main() 
{ 
    int i = 0; 
    int counter = 0; 
  
    // calling function 
    counter = ttl_upper(i, counter); 
    printf("\nNumber of upper case present in the sentence is:%d", counter); 
    return 0; 
}

輸出:

Number of upper case present in the sentence is:3


相關用法


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