C语言toupper函数和tolower函数
函数原型:
int toupper(int c);//参数c为待转换的字符
int tolower(int c);
toupper()函数:把小写字母转换为大写字母
tolower()函数:把大写字母转换为小写字母
头文件:
#include <ctype.h>
返回值:若须转换则返回转换后的字符,若不须转换则返回c参数的值
toupper()函数:若参数c是小写字母,则返回相应的大写字母;若参数c不是小写字母,则返回参数c的值
tolower()函数:若参数c是大写字母,则返回相应的小写字母;若参数c不是大写字母,则返回参数c的值
#include <stdio.h>
#include <ctype.h>
//将字符串"I am A Student"转换成"I AM A STUDENT"
int main()
{
char str[] = "I am A Student";
int len = sizeof(str) / sizeof(str[0]);
int i = 0;
for (i = 0; i < len; i++)
{
str[i] = toupper(str[i]);
}
printf("%s\n", str);
return 0;
}