一些C函数

来源:互联网 发布:rrt算法是什么 编辑:程序博客网 时间:2024/06/05 08:43

统计整形参数的值为1的二进制位的个数

 

/* bitcount: count 1 bits in x */

int bitcount(unsigned x)

{

int b;

 

for(b=0; x != 0; x >>= 1)

if(x & 01)

b++;

return b;

}

 

 

 

squeeze(s1, s2),将字符串s1中任何与字符串s2中字符匹配的字符都删除

 

void squeeze(char s1[], char s2[])

{

int i=0,j=0,k=0,flag=0;

 

for(i=j=0; s1[i] != '/0'; i++)

{

flag=0;

for(k=0; s2[k] != '/0' && !flag; k++)

{

if(s2[k] == s1[i])

flag = 1;

}

 

if( !flag)

{

s1[j++] = s1[i];

}

}

s1[j] = '/0';

}

 

 

 

 

/* lower:  convert c to lower case; ASCII only */

int lower(int c)

{

if(c >= 'A' && c <= 'Z')

return c+'a'-'A';

else

return c;

}

原创粉丝点击