首页 > 其他 > 详细

7.13编写一程序将两个字符串连接起来,不使用stracat函数

时间:2017-07-22 16:21:19      阅读:299      评论:0      收藏:0      [点我收藏+]

7.13编写一程序将两个字符串连接起来,不使用stracat函数

输入的时候,注意字符串的长度。

#include<stdio.h>//7.13 编写一个程序,将两个字符串连接起来,不要用strcat函数。  
int main()  
{  
    char c1[20],c2[20];  
    int i=0,j=0;  
    printf("Input string1:");  
    gets(c1);  
    printf("Input string2:");  
    gets(c2);  
    while(c1[i]!=‘\0‘){
        i++;
    }
    while(c2[j]!=‘\0‘){
        c1[i++]=c2[j++];
    }  
    c1[i]=‘\0‘;  //给出c1字符串的结束符,此时,c1和c2的长度和可以是20
    puts(c1);  
    return 0;  

 

7.13编写一程序将两个字符串连接起来,不使用stracat函数

原文:http://www.cnblogs.com/Allen-win/p/7221540.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!