C标准库 movmem函数




movmem()函数用于从源字符中移动字节到目标字符。

movmem()函数 语法

void movmem(void*source,void*destination,unsigned n);

参数source为要移动的源区域;

参数destination为移动的目标区域;



参数n为要移动的总数。

movmem()函数没有返回值。

movmem()函数 示例

本示例使用movmem函数从源字符s中移动11字节到目标字符s+5中,并输出移动后的字符串。其具体代码如下所示:

#include<stdio.h>
#include<string.h>
void main()
{
     char*s="Good luck to you";/*声明字符串*/
     movmem(s,s+5,strlen(s)-5);/*移动字符*/
     s[strlen(s)-5]=0;
     printf("%s",s);/*输出字符串*/
}

运行结果如图所示。

movmem()函数 示例