字符串的拷贝
#include<stdio.h>
#include<assert.h>
#include<string.h>
void mystrc1(char *des,char src)
{
int i;
for(i-0;src[i]=’\0’;i++)//(src+1)
{
des[i]=src[i];
}
des[i]=’\0’;
}
//des=src;
void mystrc2(char *des,char src)
{
int i;
for(i=0;(src+i);i++)
{
(des+i)=(src+i);
}
*(des+i)=’\0’;
}
void mystrc3(char *des,char *src)
{
while(*src!=’\0’)
{
*des=*src;
des++;
src++;
}
*des = ‘\0’;
}
void mystrc4(char *des,char *src)
{
while(*src !=’\0’)
{
des++=src++;//等价于(des++)=(src++)
}
*des=’\0’;
}
void mystrc(char *des,char *src)
{
while(*des++=*src++);//字符串拷贝简易,考试用
}
void mystrcpy(char *des,char)
{
while(*des++ = *src++);
}
char *mystrcpy(char *des,const char *src)
{
char *p = des;
assert(des!=NULL&&src!=NULL);
if(des == NULL || src = NULL)
{
return ;
}
while(*src !=’\0’)
{
*des = *src;
//*src = ‘\0’;
des++;
src++;
}
*des = ‘\0’;
return p;
}
int div(int a,int b)
{
assert(b!=0);
if(b==0)
{
return 0;
}
return a/b;
}
main()
{
char str1[100]="";
char str2[]=“abcde”;
char str3[100];
mystrc(str1.str2);//char*,char *
printf("%s\n",str1);
printf(“str1=%s\n”,str1);
return 0;
}