⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strrev.c

📁 Many C samples. It is a good sample for students to learn C language.
💻 C
字号:
/*  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;
	}
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -