×
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
1989    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
Do yourself what you wish others to do.
Sri Sri Ramakrishna Paramahamsa
3039
80.82
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54128
25/06/2018     45121
01/01/2018     43673
28/06/2017     41208
02/08/2017     40224
01/08/2017     34268
06/07/2017     34071
15/05/2017     33309
11/09/2018     30326
14/07/2017     29835
softetechnologies