home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / watcher / part01 / get_col_fld.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-27  |  787 b   |  36 lines

  1. /*
  2.    get_col_field: we have a column output format and want a certain
  3.    part of it.  Place the it in 'value' if it exists and return a
  4.    pointer to the string.  If there are problems place a null terminated
  5.    zero length string in 'value' and return NULL as an error condition.
  6.  
  7.    Kenneth Ingham
  8.  
  9.    Copyright (C) 1987 The University of New Mexico
  10. */
  11.  
  12. #include "defs.h"
  13.  
  14. char *
  15. get_col_field(line, start, end, value)
  16. char *line, *value;
  17. int start, end;
  18. {
  19.     int len;
  20.  
  21.     value[0] = '\0';
  22.     len = strlen(line);
  23.  
  24.     /* error checking */
  25.     if (start > len || end > len) {
  26.         fprintf(stderr,"'%s' has %d columns. Specified were %d to %d\n",
  27.             line, len, start, start);
  28.         return NULL;
  29.     }
  30.     len = end - start + 1;
  31.     (void) strncpy(value, &line[start-1], len);
  32.     value[len] = '\0';
  33.  
  34.     return value;
  35. }
  36.