加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

写一个函数,将两个字符串连接在一起成为一个字符串

(2011-04-18 21:18:26)
标签:

it

分类: c语言和汇编语言

写一个函数,将两个字符串连接在一起成为一个字符串, 例如:char str1[] = "abc", char str2[] = "def",然后将这两个字符串连接在一起后为"yfwxyy"并输出.


// cat.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <STRING.h>
#include <stdio.h>

void fun_strcat(char str1[],char str2[])
{
 int i = 0;
 int j = 0;
 while(str1[i] != '\0')
 {
  i++;
 }
 while ((str1[i++] = str2[j++]) != '\0');

 printf("%s\n",str1);
}

int main(int argc, char* argv[])
{
 char str1[8] = "abc";
 char str2[8] = "def";
 fun_strcat(str1,str2);
 return 0;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有