资源描述:
《1.π的定义和角度、弧度互换》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.π的定义和角度、弧度互换#definePI(4*atan(1))#definedeg2rad(d)((d)*PI/180)#definerad2deg(r)((r)*180/PI)2.位操作#include#defineMASKCHAR_BIT-1#defineSHIFT((CHAR_BIT==8)?3:(CHAR_BIT==16)?4:8)#defineBitOff(a,x)((void)((a)[(x)>>SHIFT]&=~(1<<((x)&MASK))))#defineBitOn(a,x)((void)((a)[(x)>>SHIFT]
2、=(1<<((x)&MA
3、SK))))#defineBitFlip(a,x)((void)((a)[(x)>>SHIFT]^=(1<<((x)&MASK))))#defineIsBit(a,x)((a)[(x)>>SHIFT]&(1<<((x)&MASK)))#defineLOBYTE(x)((unsignedchar)(x))#defineHIBYTE(x)((unsignedint)(x)>>8)typedefenum{ERROR=-1,FALSE,TRUE}LOGICAL;#defineBOOL(x)(!(!(x)))#defineBitSet(arg,posn)((arg)
4、(1L<<(posn)))#de
5、fineBitClr(arg,posn)((arg)&~(1L<<(posn)))#defineBitTst(arg,posn)BOOL((arg)&(1L<<(posn)))charset[(BITCOUNT+7)/8];intgetbit(char*set,intnumber){set+=number/8;return(*set&(1<<(number%8)))!=0;/*0or1*/}intsetbit(char*set,intnumber,intvalue){set+=number/8;if(value)*set
6、=1<<(number%8);/*setbit*/else*set&
7、=~(1<<(number%8));/*clearbit*/}55字符串操作3.支持通配符的匹配(*和?)返回1表示可以匹配,0表示不可以patmat(char*raw,char*pat){inti,slraw;if((*pat==' ')&&(*raw==' '))return(1);if(*pat==' ')return(0);if(*pat=='*'){if(*(pat+1)==' ')return(1);for(i=0,slraw=strlen(raw);i<=slraw;i++)if((*(raw+i)==*(pat+1))
8、
9、(*(pat+1)=='?'))if(pat
10、mat(raw+i+1,pat+2)==1)return(1);}else{if(*raw==' ')return(0);if((*pat=='?')
11、
12、(*pat==*raw))if(patmat(raw+1,pat+1)==1)return(1);}return(0);}intxstrcmp(char*mask,char*s){while(*mask){switch(*mask){case'?':if(!*s)return(0);s++;mask++;break;case'*':55while(*mask=='*')mask++;if(!*mask)return(1);if(*mas
13、k=='?')break;while(*s!=*mask){if(!*s)return(0);s++;}s++;mask++;break;default:if(*s!=*mask)return(0);s++;mask++;}}if(!*s&&*mask)return(0);return(1);}4.去除字符串中的空格#defineNUL' 'char*rmtrail(char*str){inti;if(0!=(i=strlen(str))){while(--i>=0){if(!isspace(str[i]))break;}str[++i]=NUL;}55returnstr;}char*r
14、mlead(char*str){char*obuf;for(obuf=str;obuf&&*obuf&&isspace(*obuf);++obuf);if(str!=obuf)strcpy(str,obuf);returnstr;}char*rmallws(char*str){char*obuf,*nbuf;for(obuf=str,nbuf=str;*obuf&&obuf;++obuf){if(!isspace(*ob