`
carolaif
  • 浏览: 70314 次
  • 性别: Icon_minigender_2
  • 来自: 大连
最近访客 更多访客>>
社区版块
存档分类
最新评论

C程序设计语言(第二版) 5-3 编写strcat()

阅读更多
#include<stdio.h>

void strcat(char *s, char *t);
void strcpy(char *s,char *t);

int main(){

		char s[100] = "hello";

		char *d = "world";
		strcat(s,d);
		printf("%s\n",s);
		return 0;
}

void strcpy(char *s,char *t)
{
	while(*s++ = *t++)
		;
}

void strcat(char *s, char *t) 
{ 
	while(*s) 
	{ 
		++s; 
	} 
	strcpy(s, t); 
} 

 PS  标准库( <string.h> )中提供的函数 strcpy() 和 strcat() 是把目标字符串作为函数的返回值

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics