In this recipe, you will learn how to create a program that displays the count of each character in a string in a tabular form.
Displaying the count of each character in a string
How to do it…
- Create a string called str. The last element in the string will be a null character, \0.
- Define another string called chr of matching length, to store the characters of str:
char str[80],chr[80];
- Prompt the user to enter a string. The entered string will be assigned to the str string:
printf("Enter a string: ");
scanf("%s",str);
- Compute the length of the string array, str, using strlen:
n=strlen(str);
- Define an integer array called count to...