ctype.h函数源码

iscsym()函数源码

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);

system("pause");

return 0;

}

iscsymf()函数源码

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);

system("pause");

return 0;

}

toascii()函数源码

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);

system("pause");

return 0;

}

isascii()函数源码

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);

system("pause");

return 0;

}

tolower()函数源码

int my_tolower( int ch)

{

if ( (unsigned int)(ch - ‘A‘) < 26u )

ch += ‘a‘ - ‘A‘;

return ch;

}//大写字母转换为小写字母。

int main()

{

char str[] = "AMMANA_BaBI";

char *p = str;

while(*p)

{

*p =my_tolower(*p);

p++;

}

puts(str);

system("pause");

return 0;

}

toupper()函数源码

int my_toupper( int ch)

{

if ( (unsigned int)(ch - ‘a‘) < 26u )

ch += ‘A‘ - ‘a‘;

return ch;

}//小写字母转换为大写字母。

int main()

{

char str[] = "ammana_Babi";

char *p = str;

while(*p)

{

*p =my_toupper(*p);

p++;

}

puts(str);

system("pause");

return 0;

}

iscntrl()函数源码

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 Character/n",ch);

else

printf("%c is not a Ctrol Character!/n",ch);

ch = 0x10;

if(my_iscntrl(ch))

printf("0x%x is a Ctrol Character/n",ch);

else

printf("0x%x is not a Ctrol Character!/n",ch);

ch = ‘ ‘;

if(my_iscntrl(ch))

printf("%c is a Ctrol Character/n",ch);

else

printf("%c is not a Ctrol Character!/n",ch);

system("pause");

return 0;

}

isgraph()函数源码

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 Character/n",ch);

else

printf("%c is not a Graph Character!/n",ch);

ch = ‘1‘;

if(my_isgraph(ch))

printf("%c is a Graph Character/n",ch);

else

printf("%c is not a Graph Character!/n",ch);

ch = ‘ ‘;

if(my_isgraph(ch))

printf("%c is a Graph Character/n",ch);

else

printf("%c is not a Graph Character!/n",ch);

system("pause");

return 0;

}

isprint()函数源码

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 Character/n",ch);

else

printf("%c is not a Sprint Character!/n",ch);

ch = ‘1‘;

if(my_isprint(ch))

printf("%c is a Sprint Character/n",ch);

else

printf("%c is not a Sprint Character!/n",ch);

ch = 0x10;

if(my_isprint(ch))

printf("0x%x is a Sprint Character/n",ch);

else

printf("0x%x is not a Sprint Character!/n",ch);

system("pause");

return 0;

}

isalnum()函数源码

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);

system("pause");

return 0;

}

ispunct()函数源码

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);

system("pause");

return 0;

}

isspace()函数源码

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);

system("pause");

return 0;

}

isxdigit()函数源码

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);

system("pause");

return 0;

}

isdigit()函数源码

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);

system("pause");

return 0;

}

islower()函数源码

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);

system("pause");

return 0;

}

isupper()函数源码

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);

system("pause");

return 0;

}

isalpha()函数源码

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);

system("pause");

return 0;

}

时间: 2024-10-12 19:28:06

ctype.h函数源码的相关文章

math.h()函数源码

hypot()函数源码 /* hypot函数对于给定的直角三角形的两个直角边, 求其斜边的长度. */ //一般的常规算法: double my_hypot01(double x, double y) { double hypotenuse; x = fabs(x); y = fabs(y); if (x < y) { double temp = x; x = y; y = temp; } if (x == 0.) return 0.; else { hypotenuse = y/x; retu

likely和unlikey函数源码分析

likely和unlikey函数源码分析 看代码的时候常常遇到likely和unlikely这两个函数,大概知道是用来检测返回值的,但是也不知道是什么.今天实在不爽了,就去看源码了. 在内核代码树的 include/linux/compiler.h里 void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #define likely_notrace(x) __builtin_expect(!!(

C语言字符串处理函数源码

strstr()函数源码 /* 得到s1中第一次包含s2字符串的位置指针. */ #include <stdlib.h> char * my_strstr(const char *s1,const char *s2) { if (*s1 == 0) { if (*s2) return (char *) NULL; return (char *) s1; } while (*s1) { size_t i; i = 0; while (1) { if (s2[i] == 0) { return (

巡风视图函数源码学习--view.py

记录一下巡风扫描器view.py这个脚本里的视图函数的学习,里面有一些print 代码是为了把数据打印出来小白我自己加的,勿怪勿怪.可能存在一些理解错误和不到位的地方,希望大佬多多指正.. 0x01:跳转到登陆页面 第二遍看这个脚本的源码时,想到一个问题,如果你在浏览器地址栏里输入http://127.0.0.1/login可以跳转到登陆页面,如果只输入127.0.0.1,这时候并没有运行Login这个视图函数,却也能直接跳转到登陆页面,这是为什么呢?原来,在Main视图函数上面有这样两行代码:

OpenCV 源码中分水岭算法 watershed 函数源码注解

为了研究分水岭算法,阅读了OpenCV 2.4.9 中watershed函数的源码实现部分,代码位于 opencv\sources\modules\imgproc\src\segmentation.cpp 文件中.先贴出加了注解的代码,以后补充对分水岭算法的解释. #include "precomp.hpp" /******************************************************* Watershed **********************

printf函数源码实现

#include <stdio.h> #include <stdarg.h> //va_start(arg,format),初始化参数指针arg,将函数参数format右边第一个参数地址赋值给arg //format必须是一个参数的指针,所以,此种类型函数至少要有一个普通的参数,  //从而提供给va_start ,这样va_start才能找到可变参数在栈上的位置.  //va_arg(arg,char),获得arg指向参数的值,同时使arg指向下一个参数,char用来指名当前参数

阻止函数源码在控制台输出

这是一个很贱的技能,我在谷歌控制台源码里看到的.相信大家都知道,在控制台里只输入函数名,不输入 () 然后按回车,就可以输出源码. 都不会陌生吧,这也有助于我们调试,是个很棒的技巧.不过系统内置的就会输出  function alert() { [native code] } 比如这个. 不过当我们输入 dir 的时候却看到: WTF,Command Line API ?难道也是系统的?以前我以为是,后来发现其实不是,而是一个js处理输出的,防止输出源码的方法. 让我们来找到他的源代码吧.在控制

查看R中的函数源码

最近在学习概率统计,对于R的统计函数,有时需要看看它计算用的是哪个公式,都有什么参数.除了直接help和?之外,是简单的办法莫过于: 1.直接输入函数名,如qnorm 2.methods()方法,但methods(qnorm)显示不是同类函数.其原理有待查明. 3.str(object),简洁的显示object的结构 4.mode(),class()等,可以简单查明对象的类型,如是不是一个函数.

java-round函数源码

看不懂,改天研究?如果记得的话 public static long round(double a) { long longBits = Double.doubleToRawLongBits(a); long biasedExp = (longBits & DoubleConsts.EXP_BIT_MASK) >> (DoubleConsts.SIGNIFICAND_WIDTH - 1); long shift = (DoubleConsts.SIGNIFICAND_WIDTH - 2