C語言中對字母進(jìn)行大小寫轉(zhuǎn)換的簡單方法
C語言tolower()函數(shù):將大寫字母轉(zhuǎn)換為小寫字母
頭文件:
#include <ctype.h>
定義函數(shù):
int toupper(int c);
函數(shù)說明:若參數(shù) c 為小寫字母則將該對應(yīng)的大寫字母返回。
返回值:返回轉(zhuǎn)換后的大寫字母,若不須轉(zhuǎn)換則將參數(shù)c 值返回。
范例:將s 字符串內(nèi)的小寫字母轉(zhuǎn)換成大寫字母。
#include <ctype.h> main(){ char s[] = "aBcDeFgH12345;!#$"; int i; printf("before toupper() : %s\n", s); for(i = 0; i < sizeof(s); i++) s[i] = toupper(s[i]); printf("after toupper() : %s\n", s); }
執(zhí)行結(jié)果:
before toupper() : aBcDeFgH12345;!#$ after toupper() : ABCDEFGH12345;!#$
C語言tolower()函數(shù):將大寫字母轉(zhuǎn)換為小寫字母
頭文件:
#include <stdlib.h>
定義函數(shù):
int tolower(int c);
函數(shù)說明:若參數(shù) c 為大寫字母則將該對應(yīng)的小寫字母返回。
返回值:返回轉(zhuǎn)換后的小寫字母,若不須轉(zhuǎn)換則將參數(shù)c 值返回。
范例:將s 字符串內(nèi)的大寫字母轉(zhuǎn)換成小寫字母。
#include <ctype.h> main(){ char s[] = "aBcDeFgH12345;!#$"; int i; printf("before tolower() : %s\n", s); for(i = 0; i < sizeof(s); i++) s[i] = tolower(s[i]); printf("after tolower() : %s\n", s); }
執(zhí)行結(jié)果:
before tolower() : aBcDeFgH12345;!#$ after tolower() : abcdefgh12345;!#$
相關(guān)文章
C語言數(shù)據(jù)結(jié)構(gòu)系列篇二叉樹的遍歷
本章將會詳細(xì)講解二叉樹遍歷的四種方式,分別為前序遍歷、中序遍歷、后續(xù)遍歷和層序遍歷。在學(xué)習(xí)遍歷之前,會先帶大家回顧一下二叉樹的基本概念2022-02-02