aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/other/ccount.c
blob: ec53a98d4428f34023574cbc290591a8a114a7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Count character occurances in string.
 * $Id: ccount.c 1.2 Wed, 19 Mar 1997 12:44:53 -0500 dyfet $
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and use see product license.
 *
 * Functions:
 * 	ccount() - count characters in string.
 */

#include <other/string.h>

/*
 * Count character occurances in ASCII string.
 *
 * Abstract:
 *	A list of possible characters to look for is passed to ccount,
 *	along with the null terminated ASCII string to look for those
 *	characters within.
 *
 * Parameters:
 *	str - string to examine and count occurances in.
 *	list - list (null terminated) of characters to search for.
 *
 * Exceptions:
 *	Either a NULL list or string is considered to hold no found
 *	characters (returns 0).
 */

int	ccount(const char *str, const char *list)
{
	int	count = 0;

	if(!str || !list)
		return 0;
	
	while(NULL != (str = strpbrk(str, list)))
	{
		++count;
		++str;
	}
	return count;
}