深圳宝安区深圳网站建设 骏域网络,百度门店推广,个人网站建设实训报告,广告海报创意设计1、问题
函数应该在第一个参数中进行查找#xff0c;并返回匹配第二个参数所包含的字符的数目 2、代码实现
#include stdio.h
#include string.h//函数应该在第一个参数中进行查找#xff0c;并返回匹配第二个参数所包含的字符的数目
int count_chars(char…1、问题
函数应该在第一个参数中进行查找并返回匹配第二个参数所包含的字符的数目 2、代码实现
#include stdio.h
#include string.h//函数应该在第一个参数中进行查找并返回匹配第二个参数所包含的字符的数目
int count_chars(char const *str, char const *chars)
{ if (str NULL || chars NULL)return 0;int count 0;while ((str strpbrk(str, chars)) ! NULL){//如果有匹配的记得把指针右移一下str;count;}return count;}int main()
{const char *str chengongyyuhellogyy;const char *chars chenyu;printf(count_chars(%s, %s) is %d\n, str, chars, count_chars(str, chars));return 0;
} 3、运行结果
gcc -g count_chars.c -o count_chars
./count_chars
count_chars(chengongyyuhellogyy, chenyu) is 12