您的位置:首页 > 其它

<ctype.h>测试

2012-09-02 11:20 309 查看
/*Tesing code for <ctype.h>*/
#include<stdio.h>
#include<ctype.h>
void create(char *);
void testing(char *);
void test_isalnum(char *);
void test_isalpha(char *);
void test_iscntrl(char *);
void test_isdigit(char *);
void test_isgraph(char *);
void test_islower(char *);
void test_isprint(char *);
void test_ispunct(char *);
void test_isspace(char *);
void test_isupper(char *);
void test_isxdigit(char *);
void test_tolower(char *);
void test_toupper(char *);

int main()
{
char str[257];
create(str);
testing(str);
}
void create(char *str)
{
int i;
for(i = 0; i < 256; i++)
str[i] = i;
}
void testing(char *str)
{
test_isalnum(str);
test_isalpha(str);
test_iscntrl(str);
test_isdigit(str);
test_isgraph(str);
test_islower(str);
test_isprint(str);
test_ispunct(str);
test_isspace(str);
test_isupper(str);
test_isxdigit(str);
test_tolower(str);
test_toupper(str);
}
void test_isalnum(char *str)	/*字母或者数字*/
{
int i;
printf("Now testing function isalnum:\n");
for(i = 0; i < 256; i++)
if(isalnum(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isalpha(char *str)	/*字母*/
{
int i;
printf("Now testing function isalpha:\n");
for(i = 0; i < 256; i++)
if(isalpha(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_iscntrl(char *str)	/*控制字符*/
{
int i;
printf("Now testing function iscntrl:\n");
for(i = 0; i < 256; i++)
if(iscntrl(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isdigit(char *str)	/*数字*/
{
int i;
printf("Now testing function isdigit:\n");
for(i = 0; i < 256; i++)
if(isdigit(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isgraph(char *str)	/*除空格以外的打印字符*/
{
int i;
printf("Now testing function isgraph:\n");
for(i = 0; i < 256; i++)
if(isgraph(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_islower(char *str)	/*小写*/
{
int i;
printf("Now testing function islower:\n");
for(i = 0; i < 256; i++)
if(islower(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isprint(char *str)	/*打印字符*/
{
int i;
printf("Now testing function isprint:\n");
for(i = 0; i < 256; i++)
if(isprint(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_ispunct(char *str)	/*除空格,字母,数字以外的打印字符*/
{
int i;
printf("Now testing function ispunct:\n");
for(i = 0; i < 256; i++)
if(ispunct(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isspace(char *str)	/*空白字符*/
{
int i;
printf("Now testing function isspace:\n");
for(i = 0; i < 256; i++)
if(isspace(str[i]))
printf("%d %c	", str[i], str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isupper(char *str)	/*大写*/
{
int i;
printf("Now testing function isupper:\n");
for(i = 0; i < 256; i++)
if(isupper(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_isxdigit(char *str)	/*16进字符*/
{
int i;
printf("Now testing function isxdigit:\n");
for(i = 0; i < 256; i++)
if(isxdigit(str[i]))
printf("%c ", str[i]);
printf("\nEnd testing\n");
getch();
}
void test_tolower(char *str)	/*大写变小写*/
{
int i;
printf("Now testing function tolower:\n");
printf("Before:\n");
for(i = 0; i < 256; i++)
if(isupper(str[i]))
printf("%c ", str[i]);
printf("\n");
printf("After:\n");
for(i = 0; i < 256; i++)
if(isupper(str[i]))
printf("%c ", tolower(str[i]));
printf("\nEnd testing\n");
getch();
}
void test_toupper(char *str)	/*小写变大写*/
{
int i;
printf("Now testing function toupper:\n");
printf("Before:\n");
for(i = 0; i < 256; i++)
if(islower(str[i]))
printf("%c ", str[i]);
printf("\n");
printf("After:\n");
for(i = 0; i < 256; i++)
if(islower(str[i]))
printf("%c ", toupper(str[i]));
printf("\nEnd testing\n");
getch();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: