home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / GETFIELD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.1 KB  |  49 lines

  1. /*
  2.  * getfield.c
  3.  * contains: getfield()
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include "gfuncts.h"
  10.  
  11. /*
  12.  *  char * 
  13.  * getfield(dest,source,width)
  14.  *
  15.  * ARGUMENT
  16.  *  (char *)    dest    =    Pointer to destination string
  17.  *  (char *)    source    =    Pointer to source string
  18.  *  (int)    width    =    Number of characters in field to be extracted
  19.  *
  20.  * DESCRIPTION
  21.  *  Characters are extracted from the source string and copied to
  22.  *  the destination string.  The number of characters transferred is the
  23.  *  lesser of "width" or the length of the source string.  No newlines or
  24.  *  other delineators are recognized in the transfer.  The destination is
  25.  *  terminated but no newline is added.
  26.  *
  27.  * RETURNS
  28.  *  Pointer to next part of source string, or NULL when end of
  29.  *        source string is reached.
  30.  *
  31.  * AUTHOR
  32.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  33.  */
  34. char* GF_CONV getfield(pd,ps,count)
  35. char *pd,*ps;
  36. int count;
  37. {
  38.     int i,chs,tmp;
  39.  
  40.     tmp=xmin(count,strlen(ps));
  41.     chs=xmax(0,tmp);
  42.     if(!chs)
  43.         return(char *)0;
  44.     for(i=1;i<=chs;i++)
  45.         *pd++=*ps++;
  46.     *pd='\0';
  47.     return ps;
  48. }
  49.