编写函数模拟strcpy()函数功能
strcpy(字符数组1,字符串2)
strcpy( )用于将字符串2复制到字符数组1中
/* strcpy(字符数组1,字符串2) strcpy( )用于将字符串2复制到字符数组1中 模拟strcpy()函数功能 */ #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<stdlib.h> void my_strcpy(char str1[], char str2[]) { int nNum; str1[30] = { 0 }; nNum = strlen(str2); for (int i = 0; i < nNum; i++) { str1[i] = str2[i]; } str1[30] = '\0'; } int main() { char strAry1[30] = "I love you I love you I love"; char strAry2[] = "I like C language"; puts(strAry1); strcpy(strAry1, strAry2); puts(strAry1); my_strcpy(strAry1, strAry2); puts(strAry1); system("pause"); return 0; }