#include /* Global variable which will hold our character count. ** Element 0 will count the number of 'A's etc.*/ int char_count[26] ; void count_chars(char string[]) { int cursor = 0; char current_char; int i; /* Initialise our counter array */ for(i=0; i< 26; i++) { char_count[i] = 0; } while(string[cursor] != '\0') { current_char = string[cursor]; if(current_char >= 'A' && current_char <= 'Z') { /* Character is an upper case letter - count it */ char_count[current_char-'A']++; } else if(current_char >= 'a' && current_char <= 'z') { /* Character is an lower case letter - count it */ char_count[current_char-'a']++; } cursor++; } } int main() { char string1[] = "The quick brown fox jumps over the lazy dog"; int i; count_chars(string1); for(i=0; i < 26; i++) { printf("%c: %d\n", 'A'+i, char_count[i]); } return 0; }