write a program to read the content of file and count how many times letter 'a' comes in file. please answer the question
Answers
Answer:
Read file in C using fopen
int main() { char ch, file_name[25]; ...
printf("Enter name of a file you wish to see\n"); gets(file_name);
fp = fopen(file_name, "r"); // read mode.
if (fp == NULL) { ...
printf("The contents of %s file are:\n", file_name);
while((ch = fgetc(fp)) != EOF) printf("%c", ch);
fclose(fp); return 0;
Explanation:
Counting letter - Python
Since we are not given/mentioned in the Question that by what programming language we write the required program, so here we are using python program to to read the content of file and count how many times letter 'a' comes in file.
Before we write the required program for this question, let's first take some hint for better understanding and know that what we need to do in this program and how to write the program.
What we need to do
We would take a user input first to accept the to accept texts from the user. We know that the function returns a string, string is one of the basis types in Python that store text.
After that, we will write that letter which we need to count, here in this question we are asked to count 'a' so here we will count 'a'.
Here's a syntax for counting text, that is,
We then print out that how many time letter comes in the file, by simply using function to print the messeges.
The Program
text = input("Enter your texts:\n")
letter = ("a")
count = text. count(letter)
print("Here in this file 'a' letter comes", count,"times.")
We can also write this program in short, so let's short the program, by changing something.
text = input("Enter your texts:\n")
print("Here in this file 'a' letter comes",text. count("a"),"times.")
Sample run
Enter your texts:
Brainly is the World's Largest S9cial Learning community App, here million of study partners to help you in Learning Math, Computer, Hindi, Science, History, English, Physics, Chemistry, Biology, Sanskrit and many more.
Here in this file 'a' letter comes 10 times.