home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / batch / dosreqtools / dosextensions / extsrc / substring.c < prev   
C/C++ Source or Header  |  1994-11-26  |  882b  |  62 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. main (int argc, char **argv)
  5. {
  6.   int retval = 0;
  7.  
  8.   if (argc == 3)
  9.     {
  10.       int start;
  11.       int end;
  12.  
  13.       char buf[256], *ptr;
  14.  
  15.       strcpy (buf, argv[1]);
  16.  
  17.       if (ptr = strchr (argv[2], ':'))
  18.     {
  19.       *ptr++ = '\000';
  20.  
  21.       start = atoi (argv[2]);
  22.       end = atoi (ptr);
  23.     }
  24.       else
  25.     {
  26.       start = 1;
  27.       end = atoi (argv[2]);
  28.     }
  29.  
  30.       if ((start > end) || (start > strlen(argv[1])))
  31.     {
  32.       fprintf (stderr, "%s: error: specification out of range.\n", argv[0]);
  33.  
  34.       retval = 10;
  35.     }
  36.       else 
  37.     {
  38.       if (end > strlen(argv[1]))
  39.         {
  40.           end = strlen(argv[1]);
  41.         }
  42.       
  43.       {
  44.           int i;
  45.  
  46.           for (i = start - 1; i < end ; i++ )
  47.         fputc (buf[i], stdout);
  48.  
  49.           fputc ('\000', stdout);
  50.       }
  51.     }
  52.     }
  53.   else
  54.     {
  55.       fprintf (stderr, "usage: %s string [start:]end\n", argv[0]);
  56.  
  57.       retval = 10;
  58.     }
  59.  
  60.   return (retval);
  61. }
  62.