home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_01 / blksplit.c < prev    next >
Text File  |  1989-10-28  |  1KB  |  50 lines

  1.  
  2. /*
  3.  *      HEADER:         ;
  4.  *      TITLE:          blksplit() Text splitting function;
  5.  *      DESCRIPTION:    "Can be used to split a block into lines
  6.  *                      or a line into fields";
  7.  *      DATE:           10/21/1989;
  8.  *      VERSION:        1.0;
  9.  *      FILENAME:       BLKSPLIT.C;
  10.  *      SEE-ALSO:       PB.C, PB.DOC;
  11.  *      AUTHORS:        Michael Kelly;
  12.  */
  13.  
  14.  
  15.  
  16. /*
  17.  *  int blksplit(
  18.  *        char *blk, char **strptr, const char *strsep, int maxstrings
  19.  *    );
  20.  *
  21.  *  blk-> NULL terminated text data block
  22.  *  strptr-> array of char *
  23.  *  strsep-> NULL terminated array of string seperator characters
  24.  *  maxstrings = maximum number of char * that will fit in strptr
  25.  *
  26.  *  splits raw text data block into strings : returns # of strings
  27.  *
  28.  */
  29.  
  30.  
  31. #include <string.h>
  32. #include <stddef.h>
  33. #include "blksplit.h"
  34.  
  35. int blksplit(char *blk, char **strptr, const char *strsep, int maxstrings)
  36. {
  37.     register int i = 0;
  38.  
  39.  
  40.     --maxstrings;
  41.  
  42.     strptr[i] = strtok(blk,strsep);
  43.  
  44.     while(strptr[i] && i < maxstrings)
  45.     strptr[++i] = strtok(NULL,strsep);
  46.  
  47.     return i;
  48. }
  49.  
  50.