×
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
1625    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.
Rabindranath Tagore
We come nearest to the great when we are great in humility.
Rabindranath Tagore
2385
71.22
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     51707
25/06/2018     43587
01/01/2018     42727
28/06/2017     40449
02/08/2017     39251
01/08/2017     33498
06/07/2017     33219
15/05/2017     32612
14/07/2017     28815
11/09/2018     28574
softetechnologies