home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / DICTION.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  895 b   |  43 lines

  1. // diction.cpp:   Implementation of the Dictionary class
  2. // from Chapter 6 of Getting Started
  3. #include "diction.h"
  4.  
  5. int Dictionary::find_word(char *s)
  6. {
  7.    char word[81];
  8.    for (int i = 0; i < nwords; ++i)
  9.       if (stricmp(words[i].get_word(word),s) == 0)
  10.          return i;
  11.  
  12.    return -1;
  13. }
  14.  
  15. void Dictionary::add_def(char *word, char **def)
  16. {
  17.    if (nwords < Maxwords)
  18.    {
  19.       words[nwords].put_word(word);
  20.       while (*def != 0)
  21.          words[nwords].add_meaning(*def++);
  22.       ++nwords;
  23.    }
  24. }
  25.  
  26. int Dictionary::get_def(char *word, char **def)
  27. {
  28.    char meaning[81];
  29.    int nw = 0;
  30.    int word_idx = find_word(word);
  31.    if (word_idx >= 0)
  32.    {
  33.       while (words[word_idx].get_meaning(nw,meaning) != 0)
  34.       {
  35.          def[nw] = new char[strlen(meaning)+1];
  36.          strcpy(def[nw++],meaning);
  37.       }
  38.       def[nw] = 0;
  39.    }
  40.  
  41.    return nw;
  42. }
  43.