home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / c / string.arc / STRNMOV.C < prev    next >
Text File  |  1984-12-31  |  1KB  |  30 lines

  1. /*  File   : strnmov.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 20 April 1984
  4.     Defines: strnmov()
  5.  
  6.     strnmov(dst, src, n) moves up to n characters of  src  to  dst.   It
  7.     always  moves  exactly n characters to dst; if src is shorter than n
  8.     characters dst will be extended on the right with NULs, while if src
  9.     is longer than n characters dst will be a truncated version  of  src
  10.     and  will  not  have  a closing NUL.  The result is a pointer to the
  11.     first NUL in dst, or is dst+n if dst was truncated.
  12. */
  13.  
  14. #include "strings.h"
  15.  
  16. char *strnmov(dst, src, n)
  17.     register char *dst, *src;
  18.     register int n;
  19.     {
  20.     while (--n >= 0) {
  21.         if (!(*dst++ = *src++)) {
  22.         src = dst-1;
  23.         while (--n >= 0) *dst++ = NUL;
  24.         return src;
  25.         }
  26.     }
  27.     return dst;
  28.     }
  29.