home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / DICTION.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  943b  |  45 lines

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