64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int main()
{
char a[10]="adf";
char *str="123";
str+=4;
cout << str;
return 0;
}
cout<<strSrc<<endl//你输出的变量不对。。而且输出后的值是随机的
int main()
{
char a[10]="adf";
strcpy_(a,"123");
return 0;
}
char a[10];
a[0]='a';
a[1]='d';
a[2]='f';
a[3]='\0';
#include <iostream>
using namespace std;
char* strcpy_(char* strDest,const char* strSrc)
{
if (strDest== NULL || strSrc == NULL)
{
return 0;
}
char *strDestCopy = strDest;
while ((*strDest++ = *strSrc++) != '\0')
{
}
//cout<<strSrc<<endl;
return strDestCopy;
}
int main()
{
char a[10]="adf";
strcpy_(a,"123");
cout<<"数组修改为:";
for(int i = 0; i < 10; i ++)
{
cout<<a[i];
}
cout<<endl;
system("pause");
return 0;
}
输出结果
数组修改为:123
char *
strcpy(char *to, const char *from)
{
char *save = to;
for (; (*to = *from) != '\0'; ++from, ++to);
return(save);
}