home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / strings / c_string / memrev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-04-09  |  909 b   |  37 lines

  1.  
  2.  
  3. /*f File   : memrev.c
  4.     Author : Richard A. O'Keefe.
  5.     Updated: 1 June 1984
  6.     Defines: memrev()
  7.  
  8.     memrev(dst, src, len)
  9.     moves len bytes from src to dst, in REVERSE order.  NUL characters
  10.     receive no special treatment, they are moved like the rest.  It is
  11.     to strrev as memcpy is to strcpy.
  12.  
  13.     Note: this function is perfectly happy to reverse a block into the
  14.     same place, memrev(x, x, L) will work.
  15.     It will not work for partially overlapping source and destination.
  16. */
  17.  
  18. #include "strings.h"
  19.  
  20. void memrev(dsta, srca, len)
  21.     register char *dsta, *srca;
  22.     int len;
  23.     {
  24.         register char *dstz, *srcz;
  25.         register int t;
  26.  
  27.         if (len <= 0) return;
  28.         srcz = srca+len;
  29.         dstz = dsta+len;
  30.         while (srcz > srca) {
  31.             t = *--srcz;
  32.             *--dstz = *srca++;
  33.             *dsta++ = t;
  34.         }
  35.     }
  36.  
  37.