/*
* 名称:合并字符串
* 日期: 2015-06-05
* 参数: myStrCat(char *p1,char *p2,char resault[]) //p1 p2输入 resault结果
* 用途:合并2个字符串到一个字符数组
*/
* 名称:合并字符串
* 日期: 2015-06-05
* 参数: myStrCat(char *p1,char *p2,char resault[]) //p1 p2输入 resault结果
* 用途:合并2个字符串到一个字符数组
*/
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
char * p1;
char * p2;
char resault[100]="";
p1="head-";
p2="foot";
myStrCat(p1,p2,resault);
printf("input:%s,%s\n",p1,p2);
printf("resault=%s\n",resault);
return 0;
}
int myStrCat(char *p1,char *p2,char resault[]){
int i=0,j=0;
for (i =0; *(p1+i) !='\0'; i++)
{
resault[i]=*(p1+i);
}
for (j =0; *(p2+j) !='\0'; j++,i++)
{
resault[i]=*(p2+j);
}
}
程序运行:
input:head-,foot
resault=head-foot