实现多态.
程序代码:/*
标准库文件ctype.h描述的各种字符分类函数。这些函数很简单,它们对满足条件的字符返回非0值,
否则返回0值。下面是有关函数:
isalpha(c)
c是字母字符
isdigit(c)
c是数字字符
isalnum(c)
c是字母或数字字符
isspace(c)
c是空格、制表符、换行符
isupper(c)
c是大写字母
islower(c)
c是小写字母
iscntrl(c)
c是控制字符
isprint(c)
c是可打印字符,包括空格
isgraph(c)
c是可打印字符,不包括空格
isxdigit(c)
c是十六进制数字字符
ispunct(c)
c是标点符号
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef int (*typefun)(int);
typefun* ctype[]={isalpha,
isdigit,
isalnum,
isspace,
isupper,
islower,
iscntrl,
isprint,
isgraph,
isxdigit,
ispunct
};
typedef enum {is_alpha,
is_digit,
is_alnum,
is_space,
is_upper,
is_lower,
is_cntrl,
is_print,
is_graph,
is_xdigit,
is_punct,
}types;
int gettype(char str, types type);
int main(void)
{
printf("%d",gettype('1',is_digit));
printf("%d",gettype('a',4));
system("pause");
return 0;
}
int gettype(char str, types type)
{
typefun* mytype=ctype;
return mytype[type](str);
}




