不用strcat函数,连接两个字符串

来源:百度知道 编辑:UC知道 时间:2024/06/17 03:47:40
从键盘获取两个字符串,连接后放到另外一个字符数组中,如果不用字符连接函数应该怎么编写?

//从键盘输入字符串s1和s2,合并为s3并输出
#include<stdio.h>

char *stringcat(char *p1,char *p2,char *p3)
{
int n=0,i;
while(*p1!='\0')
{
*p3=*p1;
p3++;
p1++;
n++;
}
while(*p2!='\0')
{
*p3=*p2;
p3++;
p2++;
n++;
}
for(i=n;i>0;i--,p3--); //把指针重新指向字符串的开头
return(p3);
}

int main()
{
char s1[30],s2[30],s3[60]; //数组的长度你自己根据需要确定
char *p1=s1,*p2=s2,*p3=s3;
printf("Input the first string:");
scanf("%s",s1);
printf("Input the second string:");
scanf("%s",s2);
printf("%s",stringcat(p1,p2,p3));
return 0;
}
//在DEV-CPP上测试通过

关于两个字符串的连接问题,,我写了一个程序,总是上机不对!!!请指教!!!不用STRCAT函数!!! 将两个字符串连接起来,不要用strcat函数 编写函数STRCAT,用来连接两个指定的字符串 c语言中两个字符串合并成一个字符串(不用strcat函数) 编一程序,将两个字符串连接起来,不要用strcat函数 1 编已程序,将两个字符串连接起来,不要用strcat函数。 怎么使用指针编写函数strcat(),实现两个字符串的首尾连接. 编一程序,将两个字串连接起来,不要用strcat函数 编一程序,将两个字符串连接起来,不要用strcat函数????? 将两个字符串连接起来函数(即实现 strcat函数功能)两个字符串由主函数输入连接后的字符串也由主函数输出