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

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

时间:2017-07-22 16:57:25      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:std   inpu   程序   int   return   str   字符串连接   函数   class   

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函数

标签:std   inpu   程序   int   return   str   字符串连接   函数   class   

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

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