设为首页 加入收藏

TOP

问题九:编写函数stringcat,实现字符串的连接,程序中需要使用指针形式访问字符串
2014-11-23 22:37:14 来源: 作者: 【 】 浏览:1
Tags:问题 编写 函数 stringcat 实现 字符串 连接 程序 需要 使用 指针 形式 访问

/***************************************************************
C语言

AUTHOR:liuyongshui
DATE:********
***************************************************************/
/*
问题九:编写函数stringcat,
实现字符串的连接,
程序中需要使用指针形式访问字符串

*/

#include

#define MAX 100

char *StringCat(char *source, const char *dest); //原函数声明

int main()
{
char s1[MAX]="I LOVE ";
char *s2="C++ and C language!";

StringCat(s1, s2); //字符串连接

printf("%s\n", s1);

return 0;
}


// 函数的定义

char *StringCat(char *source, const char *dest)
{
//int i=0;
//int j;

while(*source++) ; //空语句,使指针移到末尾

*source--; //向前移一位,因为上面结束前还向后移动一位

while(*dest!='\0') //当遇到'\0'时结束,此句等同于while(*dest!='\0')
{
*source++=*dest++; //把dest中的值赋给source
}

return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇问题十:用递归算法设计函数,求1*.. 下一篇问题十一:5个学生考了3门课程,编..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: