home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cstrings.arc / STRCAT.C < prev    next >
Encoding:
Text File  |  1985-08-06  |  2.5 KB  |  99 lines

  1. /*
  2.     CSTRINGS.LBR VERSION 1.0
  3.     Spark Software, Inc.
  4.  
  5.         If you find this software of use, it is requested that you send
  6.         a donation ($10.00 suggested) to:
  7.  
  8.             Spark Software, Inc.
  9.             24 Royal Crest Dr., #5
  10.             Nashua, NH  03060
  11.  
  12.         Upon receiving your donation, your name will be added to the 
  13.         List of Registered Users, and future updates can be obtained
  14.         from the SPARKIE RBBS at (603) 888-8179.
  15.  
  16.         If you include an extra $10.00 with your donation, the newest
  17.         version of CSTRINGS.LBR will be mailed to you.
  18.  
  19.         Call SPARKIE RBBS at the number above for other Spark Software
  20.         products!!!
  21. */
  22.  
  23. /*
  24.  *    char *
  25.  *    strcat (destination, source)
  26.  *    char *destination, *source;
  27.  *
  28.  *    This function appends source (including the null terminator) to
  29.  *    destination, and returns a pointer to the result.
  30.  */
  31.  
  32. char *strcat(destination, source)
  33. register char *destination, *source;
  34. {
  35.     char *start_pointer;
  36.  
  37.                     /* First save the pointer to the
  38.                        destination so that it can be
  39.                        returned at the end */
  40.     start_pointer = destination;
  41.  
  42.                     /* Now find the end of the
  43.                        destination string */
  44.     while (*destination)
  45.         ++destination;
  46.  
  47.                     /* Copy source */
  48.     while (*destination++ = *source++)
  49.         ;
  50.                     /* Return a pointer to the result */
  51.     return (start_pointer);
  52.  
  53. } /* strcat */
  54.  
  55. /*
  56.  *    char *
  57.  *    strncat (destination, source, length)
  58.  *    char *destination, *source;
  59.  *    int length;
  60.  *
  61.  *    This function appends length bytes from source to destination, and
  62.  *    returns a pointer to the result.  If the length of source is less
  63.  *    than length, then the result is null padded.  If the length of source
  64.  *    is greater than or equal to length, then the result will not have a
  65.  *    null terminator added.
  66.  */
  67.  
  68. char *strncat(destination, source, length)
  69. register char *destination, *source;
  70. int length;
  71. {
  72.     char *start_pointer;
  73.  
  74.                     /* First save the pointer to the
  75.                        destination so that it can be
  76.                        returned at the end */
  77.     start_pointer = destination;
  78.  
  79.                     /* Now find the end of the
  80.                        destination string */
  81.     while (*destination)
  82.         ++destination;
  83.  
  84.                     /* Copy source */
  85.     do {
  86.  
  87.         if (length-- == 0) {
  88.                     /* Woops!  The source is too short.
  89.                        Null padding is required */
  90.             *destination = 0;
  91.             break;
  92.         }
  93.     } while (*destination++ = *source++);
  94.  
  95.                     /* Return a pointer to the result */
  96.     return (start_pointer);
  97.  
  98. } /* strncat */
  99.