Print number of distinct characters in a string.

How do I implement a C program that reads a string and prints a table with the number of occurrences of each character in the string.
Ex: Rubber. r = 2, u = 1, b = 2, e = 1.

Showing Answers 1 - 2 of 2 Answers

Simple, fairly brain-dead example. Assumes any input characters fall into the range [0...CHAR_MAX).

Code
  1. #include <stdio.h>

  2. #include <ctype.h>

  3. #include <limits.h>

  4. "USAGE: %s <string>

  5. ""%c: %02d

  6. ""%x: %02d

  7. ", i, counts[i]);

  8.       }

  9.     }

  10.   }

  11. }

  12.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions