home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2_409E.SZH / COPY.C < prev    next >
Text File  |  1991-06-27  |  739b  |  44 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #define DEBUG 0
  4. copy_n_match_null (
  5.    char *str1,
  6.    char *str2,
  7.    int len)
  8. {
  9.    int i;
  10.    int found_it;
  11.  
  12. #if DEBUG
  13.    printf("Called with len = %d\n",len);
  14. #endif
  15.    found_it = 0;
  16.    for (i = 0; i < len; i++)
  17.       {
  18.       if (str2[i] == '\0')
  19.          break;
  20.       }
  21. #if DEBUG
  22.    printf("After scan, i = %d\n",i);
  23. #endif
  24.    if (i == len)
  25.       {
  26.       --found_it;
  27.       --i;
  28.       }
  29.  
  30.    len = i + 1;
  31. #if DEBUG
  32.    printf("Doing strncpy in copy.c");
  33.    printf(" with len = %d\n",len);
  34. #endif
  35.    strncpy (str1, str2, len);
  36. #if DEBUG
  37.    printf("Have done strncpy in copy.c\n");
  38. #endif
  39.    if (found_it != 0)
  40.       return (-1);
  41.    else
  42.       return (len);
  43. }
  44.