当前位置: C语言 -- 标准库 -- <ctype.h> -- toupper

toupper函数


概要:
#include <ctype.h>
int toupper(int c);

描述:

该函数将小写字母转换成对应的大写字母。

该函数行为会受当前语言环境影响。默认环境中(即“C”语言环境),小写字母为下述成员之一:

a b c d e f g h i j k l m n o p q r s t u v w x y z

对应的大写字母分别为:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

非默认环境中,一个小写字母可能存在一个或者多个对应的大写字母;toupper函数返回其中一个对应的大写字母,该大写字母在任何指定的语言环境中总是相同的。


参数:
int c

参数c为一个int类型整数,其值可用unsigned char类型表示或者等于宏EOF。如果参数c是其它值,函数行为是未定义的。


返回值:

如果参数c是小写字母,函数返回其对应的大写字母;反之,如果参数c不是小写字母,函数返回原值。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
/*函数toupper范例*/

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

int main(void)
{
    int i = 0;
    const char str[] = "www.standards.wiki";

    while(str[i])
    {
        putchar(toupper(str[i++]));
    }

    return 0;
}


输出:

WWW.STANDARDS.WIKI


相关内容:
tolower 将大写字母转换成小写字母的函数。