2018-01-25 19:35:53 +03:00
|
|
|
#ifndef WORD_COUNT_H
|
|
|
|
#define WORD_COUNT_H
|
|
|
|
|
2020-06-28 18:25:37 +03:00
|
|
|
#define MAX_WORDS 20 // at most MAX_WORDS can be found in the test input string
|
|
|
|
#define MAX_WORD_LENGTH 50 // no individual word can exceed this length
|
2018-01-25 19:35:53 +03:00
|
|
|
|
|
|
|
// results structure
|
2020-05-29 23:23:24 +03:00
|
|
|
typedef struct word_count_word
|
|
|
|
{
|
|
|
|
char text[MAX_WORD_LENGTH];
|
|
|
|
int count;
|
2018-01-25 19:35:53 +03:00
|
|
|
} word_count_word_t;
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
#define EXCESSIVE_LENGTH_WORD -1
|
2018-01-25 19:35:53 +03:00
|
|
|
#define EXCESSIVE_NUMBER_OF_WORDS -2
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
// word_count - routine to classify the unique words and their frequency in a
|
|
|
|
// test input string inputs:
|
2018-01-25 19:35:53 +03:00
|
|
|
// input_text = a null-terminated string containing that is analyzed
|
|
|
|
//
|
|
|
|
// outputs:
|
|
|
|
// words = allocated structure to record the words found and their frequency
|
|
|
|
// uniqueWords - number of words in the words structure
|
|
|
|
// returns a negative number if an error.
|
|
|
|
// words will contain the results up to that point.
|
2020-05-29 23:23:24 +03:00
|
|
|
int word_count(const char *input_text, word_count_word_t *words);
|
2018-01-25 19:35:53 +03:00
|
|
|
|
|
|
|
#endif
|