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

Answer Posted / vadivel

#include <stdio.h>
int count[26];
int main()
{
FILE *f;
int i;
char ch;
f = fopen("capti.c","r");
while(!feof(f))
{
ch = fgetc(f);
count[ch - 'a']++;
}
for(i = 0;i < 26;i++)
printf("count[%c] = %d\n",65+i,count[i]);
fclose(f);
return 0;
}
//asuming only lower characters are required

Is This Answer Correct ?    38 Yes 23 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is boolean a datatype in c?

523


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3474


What is p in text message?

514


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

684


Explain what is the benefit of using #define to declare a constant?

583






how to find binary of number?

3375


When should a type cast be used?

556


If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above

604


What is function in c with example?

604


any restrictions have on the number of 'return' statements that may be present in a function. a) no restriction b) only 2 return statements c) only 1 return statements d) none of the above

632


Explain the meaning of keyword 'extern' in a function declaration.

691


What are dangling pointers? How are dangling pointers different from memory leaks?

582


What is linear search?

653


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1466


What is auto keyword in c?

768