C program to find frequency of each character in a text
file?

Answer Posted / silky

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int main()
{
char a[100],s[100];
gets(a);
int i,c[27],j;

for(int i=0;i <=26;i++)
c[i]=0;

for(i=0;i<strlen(a);i++)
{
if(a[i]>='a' && a[i]<='z')
{
c[ a[i] - 'a' ]++;
}
}

for(j=0;j <=26;j++)
{
if(c[j]>0)
{
printf("%c occurs %d times\n ",'a'+j,c[j]);
}
}

}

Is This Answer Correct ?    5 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

1451


Is it possible to execute code even after the program exits the main() function?

784


Why do some versions of toupper act strangely if given an upper-case letter?

608


What does typedef struct mean?

624


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

581






What is unary operator?

636


Is calloc better than malloc?

552


Why static is used in c?

593


What is calloc malloc realloc in c?

568


What is structure padding in c?

596


why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???

1487


What is the newline escape sequence?

558


Explain how can I right-justify a string?

596


write a program to copy the string using switch case?

2371


What is maximum size of array in c?

555