×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Reverse a string - String Accept a string and convert it in lower case - String
Find the frequency of character in a sentence - String - String - C Language
1353    Arnab De    23/04/2019

Write a Program in c to accept a sentence and find the frequency of character in it.

Create a integer array of the length 26 and fill it with 0 in each elements. It represent 26 alphabate in english language. use the method strupr() to convert the sentence in upper case. read each chracter of the sentence and if the character is a alphabate then get the ASCII of the character and deduct 65 [ ASCII of the A ] from it and store a variable x. Now increment the array position which index is x.

#include
int main()
{
	char str[30],i;
	int ch[26];
	for(i=0;i<26;i++)
	{
		ch[i]=0;
	}
	printf("Enter A String: ");
	gets(str);
	strupr(str);
	for(i=0;str[i]!='\0';i++)
	{
		if(str[i]>=65 && str[i]<=90)
		{
			ch[(str[i]-65)]++;
		}
	}
	printf("Result Is \n");
	for(i=0;i<26;i++)
	{
		if(ch[i]>0)
		{
			printf("%c = %d\n",(i+65),ch[i]);
		}
	}

	return 0;
}
Reverse a string - String Accept a string and convert it in lower case - String
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
If you want to go east, don't go west.
Sri Sri Ramakrishna Paramahamsa
2001
58.5
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     43984
01/01/2018     36610
25/06/2018     35914
28/06/2017     34654
02/08/2017     33153
01/08/2017     27616
06/07/2017     27336
15/05/2017     26986
14/07/2017     22627
21/04/2018     21239
softetechnologies