[ create a new paste ] login | about

Link: http://codepad.org/ZJzaSFAy    [ raw code | output | fork ]

C, pasted on Oct 16:
#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);
}


Output:
1
2
3
Found 2 occurrences in a total length of: 32

Exited: ExitFailure 45


Create a new paste based on this one


Comments: