- [color=#0000ff]iscsym ( )//C语言库函数源代码[/color]
- int my_iscsym(int c)
- {
- return (isalnum(c) || ( c == '_' ));
- }//判断字符c是否为英文字母、数字和下划线
- int main()
- {
- char ch = 'a';
- if(my_iscsym(ch))
- printf("%c is English, UnderLine Character or Number! n",ch);
- else
- printf("%c is not a English, UnderLine Character and Number!n",ch);
- ch = '_';
- if(my_iscsym(ch))
- printf("%c is English, UnderLine Character or Number! n",ch);
- else
- printf("%c is not a English, UnderLine Character and Number!n",ch);
- ch = '1';
- if(my_iscsym(ch))
- printf("%c is English, UnderLine Character or Number! n",ch);
- else
- printf("%c is not a English, UnderLine Character and Number!n",ch);
-
- ch = '?';
- if(my_iscsym(ch))
- printf("%c is English, UnderLine Character or Number! n",ch);
- else
- printf("%c is not a English, UnderLine Character and Number!n",ch);
-
- return 0;
- }
- [color=#0000ff]iscsymf ( )//C语言库函数源代码[/color]
- int my_iscsymf(int c)
- {
- return (isalpha(c) || ( c == '_' ));
- }//判断字符c是否为英文字母和下划线
- int main()
- {
- char ch = 'a';
- if(my_iscsymf(ch))
- printf("%c is English or UnderLine Character! n",ch);
- else
- printf("%c is not a English and UnderLine Character!n",ch);
- ch = '_';
- if(my_iscsymf(ch))
- printf("%c is English or UnderLine Character! n",ch);
- else
- printf("%c is not a English and UnderLine Character!n",ch);
- ch = '1';
- if(my_iscsymf(ch))
- printf("%c is English or UnderLine Character! n",ch);
- else
- printf("%c is not a English and UnderLine Character!n",ch);
- return 0;
- }
- [color=#0000ff]toascii ( )//C语言库函数源代码[/color]
- int my_toascii( int c)
- {
- return c & 0x7f;
- }//将字符c转换为ascii码。toascii函数将字符c的高位清零,仅保留低七位。返回转换后的数值。
- int main()
- {
- unsigned char str[] = "源代码";
- unsigned char *p = str;
-
- while(*p)
- {
- *p =my_toascii(*p);
- p++;
- }
- puts(str);
- return 0;
- }
- [color=#0000ff]isascii ( )//C语言库函数源代码[/color]
- int my_isascii( int ch )
- {
- return (unsigned int)ch < 128u;
- }//判断字符c是否为ascii码。ascii码指0x00-0x7F之间的字符。
- int main()
- {
- int ch = 'a';
- if(my_isascii(ch))
- printf("%c is ASCII Character!n",ch);
- else
- printf("%c is not a ASCII Character!n",ch);
- ch = 0x80;
- if(my_isascii(ch))
- printf("0x%x is ASCII Character!n",ch);
- else
- printf("0x%x is not a ASCII Character!n",ch);
- return 0;
- }
- [color=#0000ff]tolower ( )//C语言库函数源代码[/color]
- int my_tolower( int ch)
- {
- if ( (unsigned int)(ch - 'A') < 26u )
- ch += 'a' - 'A';
- return ch;
- }//大写字母转换为小写字母。
- int main()
- {
- char str[] = "afsdfsd_fsk";
- char *p = str;
- while(*p)
- {
- *p =my_tolower(*p);
- p++;
- }
- puts(str);
- return 0;
- }
- [color=#0000ff]toupper ( )//C语言库函数源代码[/color]
- int my_toupper( int ch)
- {
- if ( (unsigned int)(ch - 'a') < 26u )
- ch += 'A' - 'a';
- return ch;
- }//小写字母转换为大写字母。
- int main()
- {
- char str[] = "afsdfsd_fsk";
- char *p = str;
- while(*p)
- {
- *p =my_toupper(*p);
- p++;
- }
- puts(str);
- return 0;
- }
- [color=#0000ff]iscntrl ( )//C语言库函数源代码[/color]
- int my_iscntrl( int ch )
- {
- return (unsigned int)ch < 32u || ch == 127;
- }//判断字符c是否为控制字符。当c在0x00-0x1F之间或等于0x7F(DEL)时,返回非零值,否则返回零。
- int main()
- {
- char ch = '_';
- if(my_iscntrl(ch))
- printf("%c is a Ctrol Charactern",ch);
- else
- printf("%c is not a Ctrol Character!n",ch);
- ch = 0x10;
- if(my_iscntrl(ch))
- printf("0x%x is a Ctrol Charactern",ch);
- else
- printf("0x%x is not a Ctrol Character!n",ch);
- ch = ' ';
- if(my_iscntrl(ch))
- printf("%c is a Ctrol Charactern",ch);
- else
- printf("%c is not a Ctrol Character!n",ch);
- return 0;
- }
- [color=#0000ff]isgraph ( )//C语言库函数源代码[/color]
- int my_isgraph( int ch )
- {
- return (unsigned int)(ch - '!') < 127u - '!';
- }//判断字符c是否为除空格外的可打印字符。可打印字符(0x21-0x7e)。
- int main()
- {
- char ch = '_';
- if(my_isgraph(ch))
- printf("%c is a Graph Charactern",ch);
- else
- printf("%c is not a Graph Character!n",ch);
- ch = '1';
- if(my_isgraph(ch))
- printf("%c is a Graph Charactern",ch);
- else
- printf("%c is not a Graph Character!n",ch);
- ch = ' ';
- if(my_isgraph(ch))
- printf("%c is a Graph Charactern",ch);
- else
- printf("%c is not a Graph Character!n",ch);
- return 0;
- }
- [color=#0000ff]isprint ( )//C语言库函数源代码[/color]
- int my_isprint( int ch )
- {
- return (unsigned int)(ch - ' ') < 127u - ' ';
- }//判断字符c是否为可打印字符(含空格)。当c为可打印字符(0x20-0x7e)时,返回非零值,否则返回零。
- int main()
- {
- char ch = '_';
- if(my_isprint(ch))
- printf("%c is a Sprint Charactern",ch);
- else
- printf("%c is not a Sprint Character!n",ch);
- ch = '1';
- if(my_isprint(ch))
- printf("%c is a Sprint Charactern",ch);
- else
- printf("%c is not a Sprint Character!n",ch);
- ch = 0x10;
- if(my_isprint(ch))
- printf("0x%x is a Sprint Charactern",ch);
- else
- printf("0x%x is not a Sprint Character!n",ch);
- return 0;
- }
- [color=#0000ff]isalnum ( )//C语言库函数源代码[/color]
- int my_isalnum ( int ch )
- {
- return (unsigned int)((ch | 0x20) - 'a') < 26u ||
- (unsigned int)( ch - '0') < 10u;
- }//测试参数ch是否是字母(A-Z,大小写均可)或数字(0-9)
- int main()
- {
- char ch = 'c';
- if(my_isalnum(ch))
- printf("%c is English Character or Number!n",ch);
- else
- printf("%c is not a English Character and Number!n",ch);
- ch = '1';
- if(my_isalnum(ch))
- printf("%c is English Character or Number!n",ch);
- else
- printf("%c is not a English Character and Number!n",ch);
- ch = '!';
- if(my_isalnum(ch))
- printf("%c is English Character or Number!n",ch);
- else
- printf("%c is not a English Character and Number!n",ch);
- return 0;
- }
- [color=#0000ff]ispunct ( )//C语言库函数源代码[/color]
- int my_ispunct( int ch )
- {
- return isprint(ch) && !isalnum (ch) && !isspace (ch);
- }//判断字符c是否为标点符号。标点符号指那些既不是字母数字,也不是空格的可打印字符。
- int main()
- {
- char ch = ',';
- if(my_ispunct(ch))
- printf("%c is punctuation Character!n",ch);
- else
- printf("%c is not a punctuation Character!n",ch);
- ch = '!';
- if(my_ispunct(ch))
- printf("%c is punctuation Character!n",ch);
- else
- printf("%c is not a punctuation Character!n",ch);
- ch = '1';
- if(my_ispunct(ch))
- printf("%c is punctuation Character!n",ch);
- else
- printf("%c is not a punctuation Character!n",ch);
- return 0;
- }
- [color=#0000ff]isspace ( )//C语言库函数源代码[/color]
- int my_isspace( int ch )
- {
- return (unsigned int)(ch - 9) < 5u || ch == ' ';
- }//判断字符c是否为空白符。空白符指空格、水平制表、垂直制表、换页、回车和换行符。
- int main()
- {
- char ch = ' ';
- if(my_isspace(ch))
- printf("%c is Space Character!n",ch);
- else
- printf("%c is not a Space Character!n",ch);
- ch = 'n';
- if(my_isspace(ch))
- printf("%c is Space Character!n",ch);
- else
- printf("%c is not a Space Character!n",ch);
- ch = '1';
- if(my_isspace(ch))
- printf("%c is Space Character!n",ch);
- else
- printf("%c is not a Space Character!n",ch);
- return 0;
- }
- [color=#0000ff]isxdigit ( )//C语言库函数源代码[/color]
- int my_isxdigit( int ch )
- {
- return (unsigned int)( ch - '0') < 10u ||
- (unsigned int)((ch | 0x20) - 'a') < 6u;
- }//判断字符c是否为十六进制数字。
- //当c为A-F,a-f或0-9之间的十六进制数字时,返回非零值,否则返回零。
- int main()
- {
- int ch = 'g';
- if(my_isxdigit(ch))
- printf("%c is Hex Number!n",ch);
- else
- printf("%c is not a Hex Number!n",ch);
- ch = '1';
- if(my_isxdigit(ch))
- printf("%c is Hex Number!n",ch);
- else
- printf("%c is not a Hex Number!n",ch);
- return 0;
- }
- [color=#0000ff]isdigit ( )//C语言库函数源代码[/color]
- int my_isdigit( int ch )
- {
- return (unsigned int)(ch - '0') < 10u;
- }//判断字符c是否为数字
- int main()
- {
- int ch = 'A';
- if(my_isdigit(ch))
- printf("%c is Digital Number!n",ch);
- else
- printf("%c is not a Digital Number!n",ch);
- ch = '1';
- if(my_isdigit(ch))
- printf("%c is Digital Number!n",ch);
- else
- printf("%c is not a Digital Number!n",ch);
- return 0;
- }
- [color=#0000ff]islower ( )//C语言库函数源代码[/color]
- int my_islower ( int ch )
- {
- return (unsigned int) (ch - 'a') < 26u;
- }//判断字符c是否为小写英文字母
- int main()
- {
- char ch = 'c';
- if(my_islower(ch))
- printf("%c is Lower English Character!n",ch);
- else
- printf("%c is not a Lower English Character!n",ch);
- ch = 'A';
- if(my_islower(ch))
- printf("%c is Lower English Character!n",ch);
- else
- printf("%c is not a Lower English Character!n",ch);
- return 0;
- }
- [color=#0000ff]isupper ( )//C语言库函数源代码[/color]
- int my_isupper( int ch )
- {
- return (unsigned int)(ch - 'A') < 26u;
- }//判断字符c是否为大写英文字母
- int main()
- {
- char ch = 'c';
- if(my_isupper(ch))
- printf("%c is Upper English Character!n",ch);
- else
- printf("%c is not a Upper English Character!n",ch);
- ch = 'A';
- if(my_isupper(ch))
- printf("%c is Upper English Character!n",ch);
- else
- printf("%c is not a Upper English Character!n",ch);
- return 0;
- }
- [color=#0000ff]isalpha ( )//C语言库函数源代码[/color]
- int my_isalpha(int ch )
- {
- return (unsigned int)((ch | 0x20) - 'a') < 26u;
- }//判断字符c是否为英文字母
- int main()
- {
- char ch = 'c';
- if(my_isalpha(ch))
- printf("%c is English Character!n",ch);
- else
- printf("%c is not a English Character!n",ch);
- ch = 'A';
- if(my_isalpha(ch))
- printf("%c is English Character!n",ch);
- else
- printf("%c is not a English Character!n",ch);
- ch = '1';
- if(my_isalpha(ch))
- printf("%c is English Character!n",ch);
- else
- printf("%c is not a English Character!n",ch);
- return 0;
- }
复制代码
0
评分
-
查看全部评分
|
|
|
|
用[code][/code]括起来更好看一些吧:P
|
|
|
|
|