Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a C program which reads and processes an input text file like this textdata.txt. It retrieves information: number of lines, number of all words,

Develop a C program which reads and processes an input text file like this textdata.txt. It retrieves information:

  • number of lines,
  • number of all words,
  • number of distinct non-common words,
  • non-common words and their frequencies.

Note that common words, are also known as stop words, like words in this file).

It outputs the retrieved information to a file like this result.txt.

Specifically, write C source programs myword.h and myword.c containing the following:

  1. structure definitions:
typedef struct word { char word[30]; int frequency; } WORD; typedef struct words { WORD word_array[1000]; int line_count; int word_count; int keyword_count; } WORDSUMMARY; 
  1. void set_stopword(char *filename, char *stopwords[]); this functions reads stop words from the common word file by filename, and puts them in the stop word dictionary data structure as an array of 26 strings, each string holds all stop words starting with the same alphabet, separated by comma ,. The array of strings is passed parameter char *stopwords[], stopwords[i] holds the pointer of the i-th string.

  2. int contain_word(char *stopwords[], char *word); this function checks if the given word is contained in stop word dictionary char stopwords[], it returns 1 if true otherwise 0.

  3. int str_contain_word(char *str, char *word); this checks if the given *word is contained in a given string str, returns 1 if yes and 0 otherwise. For example, if str is the,this,that, word is this, then it returns 1.

  4. int process_word(char *filename, WORDSUMMARY *words, char *stopwords[]); this function opens and reads text file of name passed by *filename line by line. For each line, it gets each word, if it is not a stop word, check if it is already in array words->word_array, if yes, increases its frequency by 1, otherwise inserts it to the end of the word_array and set its frequency 1. Meantime, it updates the count infomation.

  5. int save_to_file(char *filename, WORDSUMMARY *words); this saves the data of WORDSUMMARY words to file of name passed by *filename in specified format.

  6. Use the provided main function file a4q2.c to test your programs as the following.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago