Pointers 交错两个字符数组的最佳方法

Pointers 交错两个字符数组的最佳方法,pointers,Pointers,我正在寻找使用用户输入的函数交错两个字符数组的最佳方法。我正在学习C++,这是一个作业,所以我不能使用任何太先进的作业,我只是好奇,如果我走的方向正确。p> 我想使用for循环迭代两个数组中的每个索引,然后使用函数添加两个字符并输出它们。我还必须为这个作业使用指针 #include <iostream>; using namespace std; char* strinterleave(const char *a, const char *b) { char done; done

我正在寻找使用用户输入的函数交错两个字符数组的最佳方法。我正在学习C++,这是一个作业,所以我不能使用任何太先进的作业,我只是好奇,如果我走的方向正确。p> 我想使用for循环迭代两个数组中的每个索引,然后使用函数添加两个字符并输出它们。我还必须为这个作业使用指针

#include <iostream>;

using namespace std;

char* strinterleave(const char *a, const char *b) {
char done;
done = *a + *b;
}

int main() {

char interleave[]="";
char storage1[] = "";
char storage2[] = "";
int lena;
int lenb;


char *a_ptr = storage1;
char *b_ptr = storage2;



    cin.getline(storage1, numeric_limits<streamsize>::max(), ' ');
    cin.getline(storage2, numeric_limits<streamsize>::max());
    lena = strlen(a_ptr);
    lenb = strlen(b_ptr);
    int finallen = lena + lenb;
    for (int j = 0; j <= finallen; ++j) {
        strinterleave(a_ptr[j], b_ptr[j]);

    }


}
#包括;
使用名称空间std;
字符*STRINTERLEVE(常量字符*a,常量字符*b){
半焦完成;
完成=*a+*b;
}
int main(){
字符交错[]=“”;
字符存储1[]=“”;
字符存储2[]=“”;
内特莱纳;
内透镜;
char*a_ptr=storage1;
char*b_ptr=storage2;
cin.getline(storage1,numeric_limits::max(),“”);
cin.getline(storage2,numeric_limits::max());
lena=斯特伦(a_ptr);
lenb=strlen(b_ptr);
int finallen=lena+lenb;

对于(int j=0;j,以下是一些需要考虑的事项:

字符串长度可能不同。您需要决定如何处理较长字符串中的剩余字符

正在检查您的代码。。。 int finallen=lena+lenb;
对于(int j=0;j感谢Olan的帮助。遍历两个字符串是否最好在两个数组中运行两个for循环?两个循环可以工作。一个循环复制第一个字符串。从第一个字符串复制字符时,可以为第二个字符串留有空格。棘手的部分可能仍然是处理不同长度的strings。我认为你目前的单循环方法也很好。再次感谢你的帮助和指点,我没有任何人能真正从中获得想法。我想我只是想再次问一下,现在这样做是否正确?现在我的方法是做一个while循环,当我们到达smalle的空终止符时停止st数组,然后使用for循环,我将以某种方式将较大数组中的额外字符添加到其中。