在msdn上写出了区别
可是他的例子的结果是一样的
我自己试了一些,memmove 和memcp也是完全一样
谁能写出一个他们不一样的例子?
char string1[60] = "The quick brown dog jumps over the lazy fox";
char string2[60] = "The quick brown fox jumps over the lazy dog";
char string3[60] = "The quick brown fox jumps over the lazy dog";
/* 1 2 3 4 5
* 12345678901234567890123456789012345678901234567890
*/ memcpy( string1 + 16, string1 + 40, 3 );
memcpy( string1 + 16, string2 + 40, 3 );
memmove( string2 + 10, string2 + 4, 40 );------结果完全一样
memcpy( string3 + 10, string3 + 4, 40 );-------结果完全一样
可是他的例子的结果是一样的
我自己试了一些,memmove 和memcp也是完全一样
谁能写出一个他们不一样的例子?
char string1[60] = "The quick brown dog jumps over the lazy fox";
char string2[60] = "The quick brown fox jumps over the lazy dog";
char string3[60] = "The quick brown fox jumps over the lazy dog";
/* 1 2 3 4 5
* 12345678901234567890123456789012345678901234567890
*/ memcpy( string1 + 16, string1 + 40, 3 );
memcpy( string1 + 16, string2 + 40, 3 );
memmove( string2 + 10, string2 + 4, 40 );------结果完全一样
memcpy( string3 + 10, string3 + 4, 40 );-------结果完全一样
#include <string.h>
#include <stdio.h>char string1[60] = "The quick brown fox jumps over the lazy dog";
char string2[60] = "The quick brown fox jumps over the lazy dog";void main( void )
{
printf( "Function:\tmemmove with overlap\n" );
printf( "Source:\t\t%s\n", string2 + 4 );
printf( "Destination:\t%s\n", string2 + 10 );
memmove( string2 + 10, string2 + 4, 40 );
printf( "Result:\t\t%s\n", string2 );
printf( "Length:\t\t%d characters\n\n", strlen( string2 ) ); printf( "Function:\tmemcpy with overlap\n" );
printf( "Source:\t\t%s\n", string1 + 4 );
printf( "Destination:\t%s\n", string1 + 10 );
memcpy( string1 + 10, string1 + 4, 40 );
printf( "Result:\t\t%s\n", string1 );
printf( "Length:\t\t%d characters\n\n", strlen( string1 ) );
getchar();
}
输出为:
Function: memmove with overlap
Source: quick brown fox jumps over the lazy dog
Destination: brown fox jumps over the lazy dog
Result: The quick quick brown fox jumps over the lazy dog
Length: 49 charactersFunction: memcpy with overlap
Source: quick brown fox jumps over the lazy dog
Destination: brown fox jumps over the lazy dog
Result: The quick quick quick quick quick quick quick quic
Length: 50 characters我的环境:VS.net 2003 + XP Professional
The quick quick brown fox jumps over the lazy dog
The quick quick brown fox jumps over the lazy dog
环境:vc w2k
#include "string.h"
typedef unsigned char BYTE;
void main()
{
char str[15] = "ABCDEFGHIJ";
int i=0;
cout<<str<<endl;
memcpy(str,str+5,10);
cout<<"Mem Copy:"<<endl;
for(i=0;i<15;i++)
cout<<int(str[i])<<" ";
cout<<endl;
cout<<str<<endl;
strcpy(str,"ABCDEFGHIJ");
memmove(str,str+5,15);
for(i=0;i<15;i++)
cout<<int(str[i])<<" ";
cout<<endl;
cout<<str<<endl;
}Mem Copy:
70 71 72 73 74 0 0 0 0 0 0 0 0 0 0
FGHIJ
70 71 72 73 74 0 0 0 0 0 -52 -64 -1 18 0
FGHIJ
Mem Copy:
70 71 72 73 74 0 0 0 0 0 0 0 0 0 0
FGHIJMem Move:
70 71 72 73 74 0 0 0 0 0 -52 -64 -1 18 0
FGHIJ
70 71 72 73 74 20 20 0 0 0 0 0 0 0 0 是不是和系统有关系
在vc w2k就一样
memcpy也不受'\0'的影响