exercism

Exercism solutions.
git clone git://code.dwrz.net/exercism
Log | Files | Refs

word_count.h (1007B)


      1 #ifndef WORD_COUNT_H
      2 #include <stdbool.h>
      3 
      4 #define WORD_COUNT_H
      5 
      6 #define MAX_WORDS 20            // at most MAX_WORDS can be found in the test input string
      7 #define MAX_WORD_LENGTH 50      // no individual word can exceed this length
      8 
      9 // results structure
     10 typedef struct word_count_word {
     11    char text[MAX_WORD_LENGTH + 1];      // allow for the string to be null-terminated
     12    int count;
     13 } word_count_word_t;
     14 
     15 #define EXCESSIVE_LENGTH_WORD     -1
     16 #define EXCESSIVE_NUMBER_OF_WORDS -2
     17 
     18 // word_count - routine to classify the unique words and their frequency in a test input string
     19 // inputs:
     20 //    input_text =  a null-terminated string containing that is analyzed
     21 //
     22 // outputs:
     23 //    words = allocated structure to record the words found and their frequency
     24 //    uniqueWords - number of words in the words structure
     25 //           returns a negative number if an error.
     26 //           words will contain the results up to that point.
     27 int word_count(const char *input_text, word_count_word_t *words);
     28 
     29 #endif