函數原型:extern void *memcpy(void *dest, void *src, unsigned int count)
參數說明:dest為目的字串,src為源字串,count為要拷貝的位元組數。
所在庫名:#include <string.h>
函數功能:將字串src中的前n個位元組拷貝到dest中。
返回說明:src和dest所指記憶體地區不能重疊,函數返回void*指標。
其它說明:暫時無。
執行個體:
#include <string.h>
#include <stdio.h>
int main()
...{
char dest[100];
char *src="I'm sky2098,please do not call me sky2098!";
memcpy(dest,src,13); //實現位元組的複製,注意memcpy返回的是void*類型
printf("The string dest is: %s ! ",dest);
return 0;
}
在VC++ 6.0 編譯運行:
可見,實現了前13個位元組的複製。
因為我們為dest初始化分配了100個位元組的空間,所以除了我們複製過來的字元,其餘的都用“/0”填充,列印出來就像上面的那樣。
函數原型:extern void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count)
參數說明:dest為目的字串,src為源字串,ch為終止複製的字元(即複製過程中遇到ch就停止複製),count為要拷貝的位元組數。
所在庫名:#include <string.h>
函數功能:將字串src中的前n個位元組拷貝到dest中,直到遇到字元ch便停止複製。
返回說明:src和dest所指記憶體地區不能重疊,函數返回void*類型指標。
其它說明:暫時無。
執行個體:
#include <string.h>
#include <stdio.h>
int main()
...{
char dest[100];
char *src="I'm sky2098,please do not call me sky2098!";
memccpy(dest,src,'o',strlen("I'm sky2098,please do"));
printf("The string dest is: %s ! ",dest);
return 0;
}
在VC++ 6.0 編譯運行:
程式實現了只從src中前strlen("I'm sky2098,please do")個字元中拷貝,如果遇到字元'o'則停止拷貝。
函數原型:extern void *memmove(void *dest, const void *src, unsigned int count)
參數說明:dest為目的字串,src為源字串,count為要拷貝的位元組數。
所在庫名:#include <string.h>
函數功能:將字串src中的前n個位元組拷貝到dest中。
返回說明:src和dest所指記憶體地區可以重疊,函數返回void*類型指標。
其它說明:功能於memcpy相同。
執行個體:
#include <string.h>
#include <stdio.h>
int main()
...{
char dest[100];
char *src="I'm sky2098,please do not call me sky2098!";
memmove(dest,src,strlen("I'm sky2098,please do"));
printf("The string dest is: %s ! ",dest);
return 0;
}
在VC++ 6.0 編譯運行:
實現的功能同memcpy是相同的。