isalnum,isalpha,isdigit.....isxdigit,ispunt等字符函数的检测程序
来源:互联网 发布:电魂网络怎么样 编辑:程序博客网 时间:2024/05/16 11:26
Linux C练习,前面12个字符检测函数,合成一个检测函数
#include<stdio.h>
#include<pthread.h>
#include<ctype.h>
#include<string.h>
//1////////////////////////////////////////////////////
void* alnum(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isalnum(pbuff[i]))==0)
{
printf("%c is not a alnum!\n",pbuff[i]);
}
else
{
printf("%c is a alnum!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//2//////////////////////////////////////////////////
void* alpha(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!=0;i++)
{
if((ret=isalpha(pbuff[i]))==0)
{
printf("%c is not a alpha!\n",pbuff[i]);
}
else
{
printf("%c is a alpha!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//3///////////////////////////////////////////////////////
void* ascii(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!=0;i++)
{
if((ret=isascii(pbuff[i]))==0)
{
printf("%c is not a ascii!\n",pbuff[i]);
}
else
{
printf("%c is a ascii!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//4/////////////////////////////////////////////////////////
void* cntrl(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=iscntrl(pbuff[i]))==0)
{
printf("%c is not a cntrl!\n",pbuff[i]);
}
else
{
printf("%c is a cntrl!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//5////////////////////////////////////////
void* digit(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isdigit(pbuff[i]))==0)
{
printf("%c is not a digit!\n",pbuff[i]);
}
else
{
printf("%c is a digit!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//6/////////////////////////////////////////////////
void* graph(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isgraph(pbuff[i]))==0)
{
printf("%c is not a graph!\n",pbuff[i]);
}
else
{
printf("%c is a graph!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//7////////////////////////////////////////////////
void* lower(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=islower(pbuff[i]))==0)
{
printf("%c is not a lower!\n",pbuff[i]);
}
else
{
printf("%c is a lower!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//8///////////////////////////////////////////////////
void* print(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isprint(pbuff[i]))==0)
{
printf("%c is not a print!\n",pbuff[i]);
}
else
{
printf("%c is a print!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//9////////////////////////////////////////////////////
void* space(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isspace(pbuff[i]))==0)
{
printf("%c is not a space!\n",pbuff[i]);
}
else
{
printf("%c is a space!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//10/////////////////////////////////////////////////
void* punct(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=ispunct(pbuff[i]))==0)
{
printf("%c is not a punct!\n",pbuff[i]);
}
else
{
printf("%c is a punct!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//11///////////////////////////////////////////////
void* upper(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isupper(pbuff[i]))==0)
{
printf("%c is not a upper!\n",pbuff[i]);
}
else
{
printf("%c is a upper!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
//12//////////////////////////////////////////////
void* xdigit(char* pbuff)
{
int ret;
int i;
for(i=0;pbuff[i]!='\0';i++)
{
if((ret=isdigit(pbuff[i]))==0)
{
printf("%c is not a xdigit!\n",pbuff[i]);
}
else
{
printf("%c is a xdigit!\n",pbuff[i]);
}
}
printf("\n");
pthread_exit(NULL);
}
///////////////////////////////////////////////////
int main()
{
pthread_t tpid;
int flag=0;
int ret;
char buff[100];
printf("1.isalnum\n");
printf("2.isalpha\n");
printf("3.isascii\n");
printf("4.iscntrl\n");
printf("5.isdigit\n");
printf("6.isgraph\n");
printf("7.islower\n");
printf("8.isprint\n");
printf("9.isspace\n");
printf("10.ispunct\n");
printf("11.isupper\n");
printf("12.isxdigit\n");
printf("13,quit!\n");
printf("\n");
for(;;)
{
printf("Please select function:\n");
scanf("%d",&flag);
sleep(2);
//1////////////////////////////////////////////////////
if(flag==1)
{
printf("Test alnum,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)alnum,buff))!=0)
{
printf("pthread_create alnum error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//2///////////////////////////////////////////////
if(flag==2)
{
printf("Test alpha,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)alpha,buff))!=0)
{
printf("pthread_create alpha error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//3//////////////////////////////////////////////
if(flag==3)
{
printf("Test ascii,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)ascii,buff))!=0)
{
printf("pthread_create ascii error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//4////////////////////////////////////////////////////////
if(flag==4)
{
printf("Test cntrl,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)cntrl,buff))!=0)
{
printf("pthread_create cntrl error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//5//////////////////////////////////////////////////////
if(flag==5)
{
printf("Test digit,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)digit,buff))!=0)
{
printf("pthread_create digit error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//6//////////////////////////////////////////////////////
if(flag==6)
{
printf("Test graph,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)graph,buff))!=0)
{
printf("pthread_create graph error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//7////////////////////////////////////////////////////
if(flag==7)
{
printf("Test lower,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)lower,buff))!=0)
{
printf("pthread_create lower error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//8///////////////////////////////////////////////////////
if(flag==8)
{
printf("Test print,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)print,buff))!=0)
{
printf("pthread_create print error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//9//////////////////////////////////////////////////////
if(flag==9)
{
printf("Test space,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)space,buff))!=0)
{
printf("pthread_create space error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//10//////////////////////////////////////////////////
if(flag==10)
{
printf("Test punct,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)punct,buff))!=0)
{
printf("pthread_create punct error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//11//////////////////////////////////////////////////////
if(flag==11)
{
printf("Test upper,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)upper,buff))!=0)
{
printf("pthread_create upper error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//12///////////////////////////////////////////////////////
if(flag==12)
{
printf("Test xdigit,Please input the string:\n");
scanf("%s",buff);
printf("\n");
if((ret=pthread_create(&tpid,NULL,(void*)xdigit,buff))!=0)
{
printf("pthread_create xdigit error!\n");
return -1;
}
memset(buff,'\0',sizeof(buff));
}
//13/////////////////////////////////////////////////
if(flag==13)
{
printf("Now quit!!\n");
return -1;
}
}
}
-----------------------------------------------------------------------------------
#gcc -lpthread is-pthread.c -o is-pthread
#./is-pthread
效果如下:
- isalnum,isalpha,isdigit.....isxdigit,ispunt等字符函数的检测程序
- C语言字符检测函数:isalnum、isalpha、isascii、iscntrl、isdigit、isgraph、islower、isspace、ispunct、isupper
- isdigit函数,isalpha函数
- c语言中的isalpha,isdigit,islower,isupper等一系列函数
- C语言中的isalpha,isdigit,islower,isupper等一系列函数
- c语言中的isalpha,isdigit,islower,isupper等一系列函数
- isalnum()和isalpha()
- 数字检测--isdigit函数
- C++/C语言函数:isalpha()函数 isdigit(int c)宏
- python-isalpha(),isdigit()
- isxdigit等
- C语言 判断字符的大小写 isalpha()函数
- isxdigit() 函数
- 【C++】isalpha、islower、isupper、isalnum、isblank、isspace函数<cctype>头文件
- isdigit 函数的问题
- isalnum() 函数
- isalpha函数,判断字符是否是字母
- ctype.h系列字符函数--isalpha()函数的使用例子
- PreTranslateMessage
- ubuntu 12.04 LTS 安装可调试bochs 2.6
- svc: failed to register lockdv1 RPC service (errno 111).
- Linux
- Android显示GIF动画的几种方法
- isalnum,isalpha,isdigit.....isxdigit,ispunt等字符函数的检测程序
- OSX:禁止Airport Utility自动开启
- 【Hadoop】RPC Overview
- Linux C 编程中,int main(int argc,char* argv[])解析
- Java xml 文件压缩成AXML文件
- RVDS2.2 成功安装与AXD调试步骤
- 为什么是神经网络?
- mingw环境变量设置
- C的指针和数组的深入理解