#include <stdio.h>
#include <ctype.h>
/*
Function: count_match_char_in_array
Purpose:
Take input character array and count number of characters that match
an input character value without regard to case and return the count found
InputArray - Array to scan for matching characters
MatchChar - Character to match against
ReturnCount - Count of how many characters passed in MatchChar are found in InputArray
Returns:
Number of characters in InputArray
*/
int count_match_char_in_array(const char *InputArray, char MatchChar, int *ReturnCount)
{
int i;
*ReturnCount = 0;
for(i=0;InputArray[i] != '\0';i++)
{
/* If we match the input char, bump the character count */
if(tolower(InputArray[i]) == MatchChar)
{
(*ReturnCount)++;
}
}
return(i);
}
/*
Purpose:
Test CountMatchCharInArray function
Will input test string and print out the matching count and the number
of characters in the input test string
*/
main()
{
int *Count;
int CharCount;
CharCount = count_match_char_in_array("Do you know the way to San Jose?", 'a',
Count);
printf("Found %d occurrences in a total length of: %d\n", *Count, CharCount);
}