Computer Science, asked by js6189764, 26 days ago

write a program to read the content of file and count how many times letter 'a' comes in file. please answer the question​

Answers

Answered by deyonaminnu
26

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:

Answered by Anonymous
89

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 \tt{in put()} 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,

\tt{>>> \; string.count(your\;text)}

We then print out that how many time letter comes in the file, by simply using \tt print() function to print the messeges.

\rule{300}{1}

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.")

\rule{300}{1}

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.

Similar questions