具体目标:封装函数实现字符串的连接
#include<stdio.h>
#include<string.h>
//实现字符串的连接
//参数1:字符串a
//参数2:字符串b
//返回值:字符串a
char *Strcat(char *px ,char *py)
{
char *ptr=px;
//char a[30]={"hello"};
//char b[10]={"linux"};
//char *px=a; //px=a; *px=a[0]
//char *py=b;
int i;
while(1)
{
if( *px != '\0' )
{
px++;
}
else
{
while(*py != '\0')
{
strcat(px,py);
py++;
px++;
}
if(*py == '\0')
{
*px='\0';
}
break;
}
}
return ptr;
}
int main(void)
{
char a[30]={"hellou"};
char b[10]={"liniii"};
char *px=a; //px=a; *px=a[0]
char *py=b;
char *ptr=NULL;
ptr=Strcat(a,b);
printf("%s\n",ptr);
return 0;
}