刚入IT行业,还有很多不懂,想深入学习C,一点一点的积累,这个要求曾经在笔试的时候碰到过。题目主要参考尹成老师博客里面的,拿过来用我自己的思维写一遍。
#include <stdio.h>
#include <stdlib.h>
#define NUM 100 //给需要拷贝到的数组设定大小
void copy(char str1[], char str2[])
{
int n = 0;
while (str1[n] != '\0')//截取有效字符段
n++;
for (int i = 0; i <= n; i++)
{
str2[i] = str1[i];
printf(" %c", str2[i]);
}
}
void main()
{
char *s1 = "abcdef ghijklm nopqrstuvwxyz";//需要拷贝的字符数组
char s2[NUM] = { 0 };
copy(s1, s2);
getchar();
}
运行结果如下: