70,020
社区成员




#include <stdio.h>
#include <assert.h>
char *mystrcpy(char *strDestination, const char *strSource)
{
char *strD = strDestination;
assert(strDestination!=NULL && strSource!=NULL);
while (1)
{
char temp;
temp = *strSource;
*strDestination = temp; //程序运行到这里就弹出,中断
strDestination++;
strSource++;
if (temp == '\0') break;
}
return strD;
}
void mystrcat(char* str1,char* str2)
{
while(*str1!='\0') str1++;
while(*str2!='\0')
{
*str1=*str2; //运行到这里也是报错
str1++;
str2++;
}
*str1='\0';
}
void mystrcat2(char* str1,char* str2)
{
int i=0,j=0;
while(str1[i]!='\0')i++;
while(str2[j]!='\0')
{
str1[i] = str2[j]; //尝试另一种写法,又是这里错,怎么回事?大神指导下!
i++;
j++;
}
str1[i]='\0';
}
void main()
{
char *str1 = "ah";
char *str2 = "chinacyr";
//mystrcpy(str1,str2);
//mystrcat(str1,str2);
}