×
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
2034    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
Education is what remains after one has forgotten what one has learned in school.
Albert Einstein
3152
82.78
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54460
25/06/2018     45529
01/01/2018     43905
28/06/2017     41418
02/08/2017     40486
01/08/2017     34493
06/07/2017     34274
15/05/2017     33513
11/09/2018     30754
14/07/2017     30255
softetechnologies