Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find no of occurences of each letter in string c++

void countCharImproved(char *str) {
    std::map<char, int> count;
    int l = strlen(str);
    for(int i=0; i<l; i++) {
        count[str[i]]++;
    }
    for(const auto kvp : count) {
        std::cout << kvp.first << " occurs " << kvp.second << " times
";
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #find #occurences #letter #string
ADD COMMENT
Topic
Name
6+6 =