×
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
2036    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.
Albert Einstein
Do not worry about your difficulties in Mathematics. I can assure you mine are still greater.
Albert Einstein
362
82.82
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54463
25/06/2018     45533
01/01/2018     43907
28/06/2017     41422
02/08/2017     40488
01/08/2017     34499
06/07/2017     34274
15/05/2017     33520
11/09/2018     30769
14/07/2017     30260
softetechnologies