home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / 1STCHAR.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  3KB  |  111 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. /*# name=First-character-of-word-in-string function
  25. */
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include "prog.h"
  30.  
  31. /*
  32. main()
  33. {
  34.   char *test="  NORMAL   ";
  35.   char *test2="NORMAL\n";
  36.   char *test3="Sysop";
  37.  
  38.   printf("1:`%s'\n",firstchar(test," \t\n",2));
  39.   printf("2:`%s'\n",firstchar(test2," \t\n",2));
  40.   printf("3:`%s'\n",firstchar(test3," \t\n",2));
  41. }
  42. */
  43.  
  44. char * _fast firstchar(char *strng,char *delim,int findword)
  45. {
  46.   int x,
  47.       isw,
  48.       sl_d,
  49.       sl_s,
  50.       wordno=0;
  51.  
  52.   char *string,
  53.        *oldstring;
  54.  
  55.   /* We can't do *anything* if the string is blank... */
  56.  
  57.   if (! *strng)
  58.     return NULL;
  59.  
  60.   string=oldstring=strng;
  61.  
  62.   sl_d=strlen(delim);
  63.  
  64.   for (string=strng;*string;string++)
  65.   {
  66.     for (x=0,isw=0;x <= sl_d;x++)
  67.       if (*string==delim[x])
  68.         isw=1;
  69.  
  70.     if (isw==0)
  71.     {
  72.       oldstring=string;
  73.       break;
  74.     }
  75.   }
  76.  
  77.   sl_s=strlen(string);
  78.  
  79.   for (wordno=0;(string-oldstring) < sl_s;string++)
  80.   {
  81.     for (x=0,isw=0;x <= sl_d;x++)
  82.       if (*string==delim[x])
  83.       {
  84.         isw=1;
  85.         break;
  86.       }
  87.  
  88.     if (!isw && string==oldstring)
  89.       wordno++;
  90.  
  91.     if (isw && (string != oldstring))
  92.     {
  93.       for (x=0,isw=0;x <= sl_d;x++) if (*(string+1)==delim[x])
  94.       {
  95.         isw=1;
  96.         break;
  97.       }
  98.  
  99.       if (isw==0)
  100.         wordno++;
  101.     }
  102.  
  103.     if (wordno==findword)
  104.       return((string==oldstring || string==oldstring+sl_s) ? string : string+1);
  105.   }
  106.  
  107.   return NULL;
  108. }
  109.  
  110.  
  111.