home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1988 / 07 / gestaltc / gestalt.c
Text File  |  1988-06-07  |  2KB  |  57 lines

  1.  
  2. Example 1: Gestalt article, July 1988 issue
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. /*************************************************************************/
  9. /*                            GESTALT.C                                  */
  10. /*        written by John W. Ratcliff and David E. Metzener              */
  11. /*                         November 10, 1987                             */
  12. /*                                                                       */
  13. /* Demonstrates the Ratcliff/Obershelp Pattern Recognition Algorithm     */
  14. /* Link this with SIMIL.OBJ created from the SIMIL.ASM source file       */
  15. /* The actual similiarity function is called as:                         */
  16. /* int simil(char *str1,char *str2)                                      */
  17. /* where str1 and str2 are the two strings you wish to know their        */
  18. /* similiarity value.  simil returns a percentage match between          */
  19. /* 0 and 100 percent.                                                    */
  20. /*************************************************************************/
  21. int     simil(char *str1,char *str2);
  22. void    ucase(char *str);
  23.  
  24. main()
  25. {
  26.   char  str1[80];
  27.   char  str2[80];
  28.   int   prcnt;
  29.  
  30. printf("This program demonstrates the Ratcliff/Obershelp pattern\n");
  31. printf("recognition algorithm.  Enter series of word pairs to\n");
  32. printf("discover their similarity values.\n");
  33. printf("Enter strings of 'END' and 'END' to exit.\n\n");
  34. do
  35.   {
  36.     printf("Enter the two strings seperated by a space: ");
  37.     scanf("%s %s",str1,str2);
  38.     ucase(str1);
  39.     ucase(str2);
  40.     prcnt = simil(str1,str2);
  41.     printf("%s and %s are %d\% alike.\n\n",str1,str2,prcnt);
  42.   } while (strcmp(str1,"END"));
  43. }
  44.  
  45. void ucase(str)
  46. char *str;
  47. {
  48. while (*str)
  49.   {
  50.    *str=toupper(*str);
  51.    str++;
  52.   }
  53. }
  54.  
  55.  
  56.  
  57. -30-