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

What is the difference between break and continue?

608


#include #include struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

5216


Here is a good puzzle: how do you write a program which produces its own source code as output?

602


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

651


What is integer constants?

626






What will the preprocessor do for a program?

595


Why is c so powerful?

691


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

606


What is the difference between call by value and call by reference in c?

621


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3735


What are pointers? Why are they used?

632


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2457


What is the collection of communication lines and routers called?

615


Can a pointer be null?

568


Write a program to reverse a string.

644