home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / NTUMIN10.ZIP / EXIST1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-09  |  2.0 KB  |  64 lines

  1. /****************************************************************************
  2.  *
  3.  *     Program Name : EXIST1.C
  4.  *
  5.  *    This program tests the existence of a given minterm (in array b)
  6.  *    in a given larger array, a with size of m minterms.
  7.  *
  8.  *    Returns  0  if b is present in a
  9.  *              -1  if b is not present in a
  10.  *
  11.  * --------------------------------------------------------------------------
  12.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  13.  *    University.
  14.  *
  15.  *    You are free to use, copy and distribute this software and its
  16.  *    documentation providing that:
  17.  *
  18.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  19.  *
  20.  *        IT IS NOT MODIFIED IN ANY WAY.
  21.  *
  22.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  23.  *
  24.  *    This program is provided "AS IS" without any warranty, expressed or
  25.  *    implied, including but not limited to fitness for any particular
  26.  *    purpose.
  27.  *
  28.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  29.  *    appreciated. Please send to:
  30.  *
  31.  *        Boon-Tiong Tan or Othman Bin Ahmad
  32.  *        School of EEE
  33.  *        Nanyang Technological University
  34.  *        Nanyang Avenue
  35.  *        Singapore 2263
  36.  *        Republic of Singapore
  37.  *
  38.  ****************************************************************************/
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42.  
  43. char     exist(b, a, m)
  44.  
  45. unsigned char       *a, *b;
  46. unsigned short      m;                      /* no. of minterms in array a */
  47.  
  48. {
  49.    unsigned char    nspm;                 /* no. of storage/minterm */
  50.    unsigned short   i;                    /* no. of minterms counter */
  51.    int              test;                 /* memory compare status */
  52.  
  53.    nspm = *(a+3);                        /* no. of bytes/minterm */
  54.  
  55.    for (i=0; i<m; i++)                   /* check with all minterms in a */
  56.       {
  57.      test = memcmp(b, (a+4+nspm*i), nspm);
  58.      if (test == 0)                          /* b present in a */
  59.         return(0);
  60.       }
  61.  
  62.    return(-1);                                   /* b not present in a */
  63. }
  64.