日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言再学习 -- ctype.h字符判断函数

發布時間:2025/3/15 编程问答 9 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言再学习 -- ctype.h字符判断函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

參看:ctype.h 百度百科

ctype.h是C標準函數庫中的頭文件,定義了一批C語言字符分類函數(C character classification functions),用于測試字符是否屬于特定的字符類別,如字母字符、控制字符等等。既支持單字節(Byte)字符,也支持寬字符。

? ? ctype.h里的函數概況

1?字符測試函數 1> 函數原型均為int isxxxx(int) 2> 參數為int, 任何實參均被提升成整型 3> 只能正確處理處于[0, 127]之間的值 2 字符映射函數 1> 函數原型為int toxxxx(int) 2> 對參數進行檢測, 若符合范圍則轉換, 否則不變 int tolower(int); 'A'~'Z' ==> 'a'~'z' int?toupper(int); 'a'~'z' ==> 'A'~'Z' 主要函數簡介

isalpha

函數名稱: isalpha 函數原型: int isalpha(char ch); 函數功能: 檢查ch是否是字母. 函數返回: 是字母返回非0(在vs2015中為2) ,否則返回 0. 參數說明: 所屬文件 <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> int?main() { ????char?ch1='*'; ????char?ch2='a'; ????if(isalpha(ch1)!=0) ????????printf("%c?is?the?ASCII?alphabet\n",ch1); ????else ????????printf("%c?is?not?the?ASCII?alphabet\n",ch1); ????if(isalnum(ch2)!=0) ????????printf("%c?is?the?ASCII?alphabet\n",ch2); ????else ????????printf("%c?is?not?the?ASCII?alphabet\n",ch2); ????return0; }

iscntrl

函數名稱:?iscntrl 函數原型: int iscntrl(int ch); 函數功能: 檢查ch是否控制字符(其ASCII碼在0和0x1F之間,數值為 0-31). 函數返回: 是返回非0,否則返回 0. 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include<stdio.h> #include<ctype.h> char?chars[]={'A',0x09,'Z'}; #define?SIZE?sizeof(chars)/sizeof(char) int?main() { ????int?i; ????for(i=0;i<SIZE;i++) ????{ ????????printf("Char%cis%saControlcharacter\n", ????????chars[i],(iscntrl(chars[i]))?"":"not"); ????} ????return?0; }

isdigit

函數名稱: isdigit 函數原型: int isdigit(char ch); 函數功能: 檢查ch是否是數字(0-9) 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> int?main() { char?ch1='1'; char?ch2='a'; if(isdigit(ch1)!=0) printf("%c?is?the?ASCII?number\n",ch1); else printf("%c?is?not?the?ASCII?number\n",ch1); if(isdigit(ch2)!=0) printf("%c?is?the?ASCII?number\n",ch2); else printf("%c?is?not?the?ASCII?number\n",ch2); return0; }
[1]

isgraph

函數名稱: isgraph 函數原型: int isgraph(int ch); 函數功能: 檢查ch是否可顯示字符(其ASCII碼在0x21到0x7E之間),不包括空格 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> int?main() { charch1=''; charch2='a'; if(isgraph(ch1)!=0) printf("%cistheASCIIprintablecharacter\n",ch1); else printf("%cisnottheASCIIprintablecharacter\n",ch1); if(isgraph(ch2)!=0) printf("%cistheASCIIprintablecharacter\n",ch2); else printf("%cisnottheASCIIprintablecharacter\n",ch2); return0; }

islower

函數名稱: islower 函數原型: int islower(int ch); 函數功能: 檢查ch是否小寫字母(a-z) 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<ctype.h> charchars[]={'A','a','z','Z'}; #defineSIZEsizeof(chars)/sizeof(char) int?main() { int?i; for(i=0;i<SIZE;i++){ printf("Char%cis%salowercasecharacter\n",chars[i],(islower(chars[i]))?"":"not"); } return0; }

isupper

函數名稱:?isupper 函數原型: int isupper(int ch); 函數功能: 檢查ch是否是大寫字母(A-Z) 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> #include<ctype.h> charchars[]={'A','a','z','Z'}; #defineSIZEsizeof(chars)/sizeof(char) int?main() { inti; for(i=0;i<SIZE;i++){ printf("Char%cis%sanuppercasecharacter\n", chars[i],(isupper(chars[i]))?"":"not"); } return0; }

tolower

函數名稱: tolower 函數原型: int tolower(int ch); 函數功能: 將ch字符轉換為小寫字母 函數返回: 返回ch所代表的字符的小寫字母 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<stdlib.h> #include<ctype.h> intmain() { charx='a',y='b',z='A',w='*'; printf("Character%ctoloweris%c\n",x,tolower(x)); printf("Character%ctoloweris%c\n",y,tolower(y)); printf("Character%ctoloweris%c\n",z,tolower(z)); printf("Character%ctoloweris%c\n",w,tolower(w)); return0; }

toupper

函數名稱: toupper 函數原型: int toupper(int ch); 函數功能: 將ch字符轉換成大寫字母 函數返回: 與ch相應的大寫字母 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<stdlib.h> #include<ctype.h> int?main() { charx='a',y='b',z='A',w='*'; printf("Character%ctoupperis%c\n",x,toupper(x)); printf("Character%ctoupperis%c\n",y,toupper(y)); printf("Character%ctoupperis%c\n",z,toupper(z)); printf("Character%ctoupperis%c\n",w,toupper(w)); return0; }

isalnum

函數名稱: isalnum 函數原型: int isalnum(int ch); 函數功能: 檢查ch是否是字母或數字 函數返回: 是字母或數字返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> intmain() { charch1='*'; charch2='a'; if(isalnum(ch1)!=0) printf("%cistheASCIInumberoralphebet\n",ch1); else printf("%cisnottheASCIInumbernoralphebet\n",ch1); if(isalnum(ch2)!=0) printf("%cistheASCIInumberoralphebet\n",ch2); else printf("%cisnottheASCIInumbernoralphebet\n",ch2); return0; }

isprint

函數名稱: isprint 函數原型: int isprint(int ch); 函數功能: 檢查ch是否是可打印字符(包括空格),其ASCII碼在0x20到0x7E之間 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> intmain() { charch1='\n'; charch2='a'; if(isprint(ch1)!=0) printf("%cistheASCIIprintablecharcater\n",ch1); else printf("%cisnottheASCIIprintablecharcater\n",ch1); if(isprint(ch2)!=0) printf("%cistheASCIIprintablecharcater\n",ch2); else printf("%cisnottheASCIIprintablecharcater\n",ch2); return0; }

ispunct

函數名稱: ispunct 函數原型: int?ispunct(int ch); 函數功能: 檢查ch是否是標點字符(不包括空格),即除字母,數字和空格以外的所有可打印字符 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> intmain() { charch1=','; charch2='a'; if(ispunct(ch1)!=0) printf("%cistheASCIIpunct\n",ch1); else printf("%cisnottheASCIIpunct\n",ch1); if(ispunct(ch2)!=0) printf("%cistheASCIIpunct\n",ch2); else printf("%cisnottheASCIIpunct\n",ch2); return0; }

isspace

函數名稱: isspace 函數原型: int isspace(int ch); 函數功能: 檢查ch是否是空格符和跳格符(控制字符)或換行符 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> intmain() { charch1=''; charch2='a'; if(isspace(ch1)!=0) printf("%cisthespacecharcater\n",ch1); else printf("%cisnotthespacecharcater\n",ch1); if(isspace(ch2)!=0) printf("%cisthespacecharcater\n",ch2); else printf("%cisnotthespacecharcater\n",ch2); return0; }

isxdigit

函數名稱: isxdigit 函數原型: int?isxdigit(int ch); 函數功能: 檢查ch是否是一個16進制數學字符(即0-9,或A-F,或a-f) 函數返回: 是返回非0,否則返回0 參數說明: 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<ctype.h> intmain() { charch1='1'; charch2='a'; if(isxdigit(ch1)!=0) printf("%cistheASCIIhexadecimalnumber\n",ch1); else printf("%cisnottheASCIIhexadecimalnumber\n",ch1); if(isxdigit(ch2)!=0) printf("%cistheASCIIhexadecimalnumber\n",ch2); else printf("%cisnottheASCIIhexadecimalnumber\n",ch2); return0; }

isascii

函數名稱:?isascii 函數原型: int isascii(int ch) 函數功能: 測試參數是否是ASCII碼0-127 函數返回: 是返回非0,否則返回0 參數說明: ch-被測參數 所屬文件: <ctype.h>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include<stdio.h> #include<ctype.h> charchars[]={'A',0x80,'Z'}; #defineSIZEsizeof(chars)/sizeof(char) intmain() { inti; for(i=0;i<SIZE;i++) { printf("Char%cis%sanASCIIcharacter\n", chars[i],(isascii(chars[i]))?"":"not"); } return0; }

isblank

函數名稱:?isblank 函數原型: int isblank(int ch) 函數功能: 測試參數是否是一個標準的空白字符(空格、水平制表符或者換行)或者任何其他本地化指定為空白符的字母 函數返回: 是返回非0,否則返回0 參數說明: ch-被測參數 所屬文件: <ctype.h>

總結

以上是生活随笔為你收集整理的C语言再学习 -- ctype.h字符判断函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。