实现字符串的链接 指针的妙用
时间:2010-04-11 来源:wwwzyf
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
char *strca(char *dst, const char *src)
{
char *dst_t = (char *)malloc(sizeof(dst)+sizeof(src));
char *start = dst_t;
assert(dst && src);
while(*dst_t = *dst){
dst_t++;
dst++;
}
while(*dst_t = *src)
{
dst_t++; src++;
}
*dst_t = '\0';
return start;
}
int main()
{
char *dst = {"wo ai "};
char *src = {"wo de guo jia !"};
printf("%s\n",strca(dst,src));
return 0;
}
实现了字符串的链接,中间用到的指针的相关知识,今天没有时间了。以后再做解释吧
#include <assert.h>
#include <stdlib.h>
char *strca(char *dst, const char *src)
{
char *dst_t = (char *)malloc(sizeof(dst)+sizeof(src));
char *start = dst_t;
assert(dst && src);
while(*dst_t = *dst){
dst_t++;
dst++;
}
while(*dst_t = *src)
{
dst_t++; src++;
}
*dst_t = '\0';
return start;
}
int main()
{
char *dst = {"wo ai "};
char *src = {"wo de guo jia !"};
printf("%s\n",strca(dst,src));
return 0;
}
实现了字符串的链接,中间用到的指针的相关知识,今天没有时间了。以后再做解释吧
相关阅读 更多 +