连接字符串(长度有限的字符串)

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
#define len 255

char* strcat(char *a, char *b){
    int lena = sizeof(a);
    int lenb = sizeof(b);
    for(int i = lena-1; i < len; )
        for(int j = 0; j < lenb; )
            a[i++] = b[j++];
    return a;
}
int main(){

    char a[len], b[len];
    cout << "please key in the first string:" << endl;
    cin >> a;
    cout << "please key in the second string:" << endl;
    cin >> b;
    strcat(a, b);
    cout << a << endl;
}

 

posted on 2017-12-11 21:43  帝孤  阅读(155)  评论(0编辑  收藏  举报

导航