用C语言写一个函数,将两个字符串连接。

来源:百度知道 编辑:UC知道 时间:2024/05/17 02:01:07
用C语言写一个函数,将两个字符串连接。

#include<stdio.h>
方法一:如mtcat所说,直接用strcat函数
方法二:编程实现strcat的功能
void main()
{ char s1[80],s2[80];
int i=0,j=0;
puts("input two strings:");
gets(s1);
gets(s2);
while(s1[i]!='\0') i++;
while((s1[i++]=s2[j++])!='\0');
printf("result:%s\n",s1);
}

1、实际上就是实现strcat这个字符串库函数,在vc自带的crt源码或者linux平台的glibc库中都有strcat的源码,自己可以查阅参考,看看库开发者是如何写代码的,对于学习C语言非常有用。
2、示例
#include <stdio.h>

char *strcat(char *str1, char *str2)
{
if((str1==NULL)||(str2==NULL)) throw "Invalide arguments!";
char *pt = str1;
while(*str1!='\0') str1++;
while(*str2!='\0') *str1++ = *str2++;
*str1 = '\0';
return pt;
}

int main()
{
char a[]= "markyuan";
char b[]= "yyyyy";
char *cat = strcat(a,b);
printf("%s\n",cat);
re

用C语言写一个函数,将两个字符串连接。 用c语言编程 写一个函数,输入一个4位数字,要求输入这4个数字字符,但每两个数字间空一个空格 求C语言高手帮忙解答,问题是:写一个函数,将两个字符串连接.谢谢~~~ C语言程序:写一个函数,输入一个4位数字,要求输出这4个数字字符,每两个数字字符间 来个C语言高手帮忙解答,问题是:写一个函数,将两个字符串连接.谢谢~~~ 用C语言写一个函数,用冒泡法对输入的10个字符按由小到大的顺序排列 用c语言编写一个程序:两个字符串a、b,将a中所有b中含有的字符删除。 c语言字符截取函数 用C语言帮我写一个函数 用C语言的指针方法处理:写一函数,将一个3*3的整形矩阵转置