Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / dheeraj kumar

#include <stdio.h>

int Small_Alpha_Char[26];
int Capital_Alpha_Char[26];
int Numeric_Char[10];
int Special_Aplha_Char[100];

int main(){

char Name_Of_Source_File[100];
printf("Enter the Name of the Source File: ");
gets(Name_Of_Source_File);

FILE *ptr1;
ptr1 = fopen(Name_Of_Source_File, "r");

while(ptr1 == NULL){
printf("
We are facing issues to find the Source File!
");
printf("This file doesn't exist in your PC!
");

printf("Enter the Name of the Source File again: ");
gets(Name_Of_Source_File);

ptr1 = fopen(Name_Of_Source_File, "r");
}

char Each_Character;
int Count = 0;

while(!feof(ptr1)){

Each_Character = fgetc(ptr1);
if(Each_Character >= 'a' && Each_Character <= 'z'){
Small_Alpha_Char[Each_Character - 'a']++;
}
else if(Each_Character >= 'A' && Each_Character <= 'Z'){
Capital_Alpha_Char[Each_Character - 'A']++;
}
else if(Each_Character >= '0' && Each_Character <= '9'){
Numeric_Char[Each_Character - '0']++;
}
else{
Special_Aplha_Char[Each_Character - 0]++;
}
}

printf("List of Characters:
");
printf("Small Alphabetic Characters:
");
for(int i = 0; i < 26; i++){
if(Small_Alpha_Char[ i ] != 0){
printf("Count[%c] = %d
", 97 + i, Small_Alpha_Char[ i ]);
Count++;
}
}
printf("There are %d Small Characters which have Frequency greater than 0!

", Count);

Count = 0;
printf("Capital Alphabetic Characters:
");
for(int i = 0; i < 26; i++){
if(Capital_Alpha_Char[ i ] != 0){
printf("Count[%c] = %d
", 65 + i, Capital_Alpha_Char[ i ]);
Count++;
}
}
printf("There are %d Capital Characters which have Frequency greater than 0!

", Count);

Count = 0;
printf("Numeric Characters:
");
for(int i = 0; i < 9; i++){
if(Numeric_Char[ i ] != 0){
printf("Count[%c] = %d
", 48 + i, Numeric_Char[ i ]);
Count++;
}
}
printf("There are %d Numeric Characters which have Frequency greater than 0!

", Count);

Count = 0;
printf("Special Alphabetic Characters:
");
for(int i = 0; i < 99; i++){
if(Special_Aplha_Char[ i ] != 0){
printf("Count[%c] = %d
", i, Special_Aplha_Char[ i ]);
Count++;
}
}
printf("There are %d Special Characters which have Frequency greater than 0!
", Count);

fclose(ptr1);

return 0;
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can include files be nested?

1053


Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.

1352


What does printf does?

1189


What is pointers in c with example?

1017


How can I read in an object file and jump to locations in it?

982


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

2364


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

2199


What is calloc()?

1023


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1817


Can a pointer be null?

974


How can I find the modification date and time of a file?

1024


When a c file is executed there are many files that are automatically opened what are they files?

1034


What is gets() function?

1070


Is register a keyword in c?

992


Explain how can you tell whether two strings are the same?

968