判断字母 数字

#include <stdio.h>

#include <ctype.h>



/*

判断是字母或数字的库函数:

满足指定的条件,返回非0;否则返回0.

isalpha(c)

isdigit(c)

*/



/***************

 * 输入:要判断的字符。

 * 输出:是字母,返回1;其他,返回0.

 **************/

int my_isalpha(unsigned char c)

{

	if ((c >= 'a' && c <= 'z') || (c >= 'A' && c<= 'Z') ) {

		return 1;

	}

	return 0;

}



/***************

 * 输入:要判断的字符。

 * 输出:是数字,返回1;其他,返回0.

 **************/

int my_isdigit(unsigned char c)

{

	if (c >= '0' && c <= '9') {

			return 1;

	}

		return 0;

}



int main(void)

{



	printf("%d\n", my_isalpha('a'));

	printf("%d\n", my_isalpha('A'));

	printf("%d\n", my_isdigit('F'));

	printf("%d\n", my_isdigit('5'));



	return 0;

}

你可能感兴趣的:(数字)