How To Count The Most Common Letter In A String

[Solved] How To Count The Most Common Letter In A String | C - Code Explorer | yomemimo.com
Question : how to count the most common letter in a string c

Answered by : cloudy-chamois-1sx54v0fhr65

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ENG_LETTERS 26
#define STR_LEN 100
int main()
{ int countArray[ENG_LETTERS] = {0}; char str[STR_LEN] = { 0 }; char engChar = 'a' - 1; int length = 0; int i , j = 0; int max = 0; int index = 0; printf("Please enter a string:\n"); fgets(str , STR_LEN , stdin); length = strlen(str); for(i = 0 ; i <= length;i++) { if(str[i] == '\n') { str[i] = '\0'; } } for(i = 0;i < ENG_LETTERS;i++) { engChar++; for(j = 0;j <= length - 1;j++) { if(str[j] == engChar) { countArray[i]++; } } } engChar = 'a'- 1; for(i = 0; i <= ENG_LETTERS - 1;i++) { engChar++; printf("There are %d %c letters\n", countArray[i],engChar); } system("PAUSE"); return 0;
}

Source : https://stackoverflow.com/questions/41640700/c-program-that-finds-out-2-most-common-letters-in-a-string-and-reverses-them-in | Last Update : Sat, 06 Feb 21

Answers related to how to count the most common letter in a string c

Code Explorer Popular Question For C