C語言中對字母進行大小寫轉換的簡單方法
更新時間:2015年08月24日 14:53:28 投稿:goldensun
這篇文章主要介紹了C語言中對字母進行大小寫轉換的簡單方法,是C語言入門學習中的基礎知識,需要的朋友可以參考下
C語言tolower()函數(shù):將大寫字母轉換為小寫字母
頭文件:
#include <ctype.h>
定義函數(shù):
int toupper(int c);
函數(shù)說明:若參數(shù) c 為小寫字母則將該對應的大寫字母返回。
返回值:返回轉換后的大寫字母,若不須轉換則將參數(shù)c 值返回。
范例:將s 字符串內的小寫字母轉換成大寫字母。
#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í)行結果:
before toupper() : aBcDeFgH12345;!#$ after toupper() : ABCDEFGH12345;!#$
C語言tolower()函數(shù):將大寫字母轉換為小寫字母
頭文件:
#include <stdlib.h>
定義函數(shù):
int tolower(int c);
函數(shù)說明:若參數(shù) c 為大寫字母則將該對應的小寫字母返回。
返回值:返回轉換后的小寫字母,若不須轉換則將參數(shù)c 值返回。
范例:將s 字符串內的大寫字母轉換成小寫字母。
#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í)行結果:
before tolower() : aBcDeFgH12345;!#$ after tolower() : abcdefgh12345;!#$

