每天一個小程序-連接字符串!

#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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章