Learn By Coding

Be a better programmer

Menu

Skip to content
  • Home

Daily Archives: August 3, 2014

Count the number of occurrences of each letter in string

Posted on August 3, 2014 by anirban0328
const char *str = "The quick brown fox jumped over the lazy dog.";

int counts[256] = { 0 };
int i;
size_t len = strlen(str);

for (i = 0; i < len; i++) {
counts[(int)(str[i])]++;
}

for (i = 0; i < 256; i++) {
printf(“The %d. character has %d occurrences.\n”, i, counts[i]);
}

Posted in Algorithms | Leave a comment

Archives

Categories

Follow Learn By Coding on WordPress.com
August 2014
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
    Sep »
Create a free website or blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
    • Learn By Coding
    • Already have a WordPress.com account? Log in now.
    • Learn By Coding
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
Design a site like this with WordPress.com
Get started