Category : C Source Code
Archive   : E_C_STR.ZIP
Filename : STRREV.C

 
Output of file : STRREV.C contained in archive : E_C_STR.ZIP
/* File : strrev.c
Author : Richard A. O'Keefe.
Updated: 1 June 1984
Defines: strrev()

strrev(dst, src)
copies all the characters of src to dst, in REVERSE order. Dst is
properly terminated with a NUL character. There is no result.
Example: strrev(x, "able was I er") moves "re I saw elba" to x.

Note: this function is perfectly happy to reverse a string into the
same place, strrev(x, x) will work. That is why it looks so hairy.
It will not work for partially overlapping source and destination.
*/

#include "strings.h"

void strrev(dsta, srca)
register char *dsta, *srca;
{
register char *dstz, *srcz;
register int t; /* should be char */

for (srcz = srca; *srcz++; ) ;
srcz--;
dstz = dsta+(srcz-srca);
/* Now srcz points to the NUL terminating src,
and dstz points to where the terminating NUL for dst belongs.
*/
*dstz = NUL;
while (srcz > srca) {
/* This is guaranteed safe by K&R, since srcz and srca
point "into the same array".
*/
t = *--srcz;
*--dstz = *srca++;
*dsta++ = t;
}
}



  3 Responses to “Category : C Source Code
Archive   : E_C_STR.ZIP
Filename : STRREV.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/