C语言isupper()函数:判断字符是否为大写字母
isupper()函数
头文件和函数原型
#include <ctype.h>
int isupper(int c);
描述
isupper()
是C语言标准库中的一个函数,用于判断一个字符是否为大写字母(A~Z,ASCII码为65~90);
返回值
传入的字符参数是一个大写字母时,返回非0
值,否则返回0
;
示例代码
这个示例将指出字符串中大写字母的位置;
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char arr[] = "Success is the Result of Hard Work, " \
"Persistence, and Determination.";
printf("%s\n", arr);
size_t length = strlen(arr);
for (int i = 0; i < length; i++) {
printf("%c", isupper(arr[i]) ? '^' : ' ');
}
printf("\n");
}
程序运行结果
Success is the Result of Hard Work, Persistence, and Determination. ^ ^ ^ ^ ^ ^