top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Can someone please design the method to find the frequency of occurrences of any given word in a book?

+2 votes
186 views
Can someone please design the method to find the frequency of occurrences of any given word in a book?
posted Oct 11, 2014 by Amit Kumar Pandey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

You can use < strstr() > to find out the frequency of occurrences of a given word.

Procedure to do:
1:  open your book using    fd =  fopen("book_name", "r");
2:  get your word which you want to find the occurrence.
3:  inside a loop probably    while(till end of file) {}
          inside the while()  
              1.  read line by line (you can use  < fgets() >), then
              2.  call strstr()  // validate the required word, if matched increment the count
                   /*
                       It will give the location of the first occurrence of the given sub_string (word).
                       so you have to call this inside a loop (on the result of fgets()) ... to check  multiple occurrence 
                       of the word in a single line.
                  */ 
                    // see the < man strstr > to know how to use.
              3.  follow this till end of the file.
4:  close()  the file descriptor.
answer Oct 13, 2014 by Arshad Khan
You may need to modify a bit to accommodate the case of more then one occurrences of the word in the single line.
Yes you are right, I have already pointed out that modification inside
point no 3's 2nd point.
i.e you have to apply another loop on the resulted line.
Similar Questions
+3 votes

Given a 2d array, u need to sort the 2 diagonals independently.
And the elements in diagonal should remain in diagonal only.

INPUT =>
24 2 3 4 7

6 13 8 5 10

11 12 9 14 15

16 21 18 25 20

17 22 23 24 1

OUTPUT =>
1 2 3 4 5

6 7 8 9 10

11 12 13 14 15

16 17 18 19 20

21 22 23 24 25

+4 votes

How can we perform Sorting a list of strings without using any built-in sort method?

0 votes

Given a sentence and a word, remove all occurrences of the word in the sentence.

For example, removing “is” from the sentence “This is a boy.” becomes “Th a boy.”

0 votes

Given a string S and set of strings U. Find the length of longest prefix of S that can be formed using strings in U.

For example you have following -

S= “absolute”
U={“abs”,”xyz”,”ol”,”te”}

Answer: 5 i.e "absol"

Now the task is to have the algorithm/program for the above problem, please help me with this?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...