码迷,mamicode.com
首页 > 其他好文 > 详细

每天一个小程序-连接字符串!

时间:2015-07-28 14:41:16      阅读:596      评论:0      收藏:0      [点我收藏+]

标签:字符串连接

#include<stdio.h>
#include<string.h>
#define MAX_LEN 100

void Conect(char a[],char b[]);
int main()
{
 char str1[MAX_LEN],str2[MAX_LEN];
 printf("please iuput str1:\n");
 scanf("%s",str1);
 printf("please iuput str2:\n");
 scanf("%s",str2);
 printf("%d\n",strlen(str1));
 printf("%d\n",strlen(str2));
 Conect(str1,str2);
 return 0;
}

void Conect(char a[],char b[])
{
 char output_str[MAX_LEN];
 int i;
 for(i=0;i<strlen(a)+strlen(b);i++)
 {
  if(i<strlen(a))
  output_str[i]=a[i];
  else
  output_str[i]=b[i-strlen(a)];
 }
 output_str[i]=‘\0‘;
 
 printf("%s\n",output_str);
 return;
}

本文出自 “7378168” 博客,请务必保留此出处http://7388168.blog.51cto.com/7378168/1679125

每天一个小程序-连接字符串!

标签:字符串连接

原文地址:http://7388168.blog.51cto.com/7378168/1679125

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!