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

A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?

1779


in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures

963


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2494


Why do we use return in c?

787


What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }

969


Explain how can you restore a redirected standard stream?

837


Describe wild pointers in c?

876


What are the types of data structures in c?

861


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9972


Define Spanning-Tree Protocol (STP)

911


write a program to concatenation the string using switch case?

1844


What is a union?

828


Discuss the function of conditional operator, size of operator and comma operator with examples.

931


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

868


What is unary operator?

886