/****************************************
* File Name : count_chars.c
* Creat Data : 2015.1.22
* Author : ZY
*****************************************/
/*编写一个函数
int count_chars(char const *str,char const *chars)
函数应该在第一个参数中进行查找,
并返回匹配第二个参数所包含的字符的数量。*/
#include <stdio.h>
#include <assert.h>
int count_chars(char const *str,char const *chars)
{
int count = 0;
char p[26] = {0};
assert(str);
assert(chars);
while(*str)
{
p[*str - 'a'] = *str;
str++;
}
while(*chars)
{
if(p[*chars - 'a'] != 0)//字符0是终止符'\0'
{
count++;
}
chars++;
}
return count;
}
#include <stdio.h>
#include <assert.h>
#include <string.h>
int count_chars(char const *str,char const *chars)
{
int count = 0;
int i,j;
assert(str);
assert(chars);
for (i = 0;i <