strcpy()函數用法


C 庫函數 char *strcpy(char *dest, const char *src)src 所指向的字符串復制到 dest。(后面的復制給前面的)

需要注意的是如果目標數組 dest 不夠大,而源字符串的長度又太長,可能會造成緩沖溢出的情況。

例:

#include <stdio.h>
#include <string.h>
int main()
{
char src[40];
char dest[100];
memset(dest, '\0', sizeof(dest));
strcpy(src, "hello world!");
strcpy(dest, src);
printf("最終的目標字符串: %s\n", dest);
return(0);
}
運行后:
最終的目標字符串: hello world!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM