天天看點

C 庫函數 - toupper()

C 标準庫 - <ctype.h>

描述

C 庫函數

int toupper(int c)

把小寫字母轉換為大寫字母。

聲明

下面是 toupper() 函數的聲明。

int toupper(int c);
      

參數

  • c -- 這是要被轉換為大寫的字母。

傳回值

如果 c 有相對應的大寫字母,則該函數傳回 c 的大寫字母,否則 c 保持不變。傳回值是一個可被隐式轉換為 char 類型的 int 值。

執行個體

下面的執行個體示範了 toupper() 函數的用法。

#include <stdio.h>
#include <ctype.h>

int main()
{
   int i = 0;
   char c;
   char str[] = "runoob";
   
   while(str[i])
   {
      putchar (toupper(str[i]));
      i++;
   }
   
  return(0);
}
      

讓我們編譯并運作上面的程式,這将産生以下結果:

RUNOOB