我想逐个字母地拼接2个不同的字符串。我怎样才能做到这一点? 例如:a = "hid", b = "jof"
级联字符串应该是"hjiodf"
。如何拼接来自2个不同字符串的字母
到目前为止,我已经尝试过这么多:
#include <stdio.h>
#include <conio.h>
void concatenate2(char p[], char q[]) {
int c = 0, d = 0;
//Iterating through both strings
while (p[c] != '\0' || q[d] != '\0') {
//Increment first string and assign the value
c++;
p[c] = q[d];
//Increment second string and assign the value
d++;
p[c] = q[d];
}
} //<<====== missing }
int main(void)
{
char w[100], a[100];
//input first string
printf("Input a string\n");
gets(w);
//input second string
printf("Input Second string\n");
gets(a);
//function call
concatenate2(w, a);
//print result
printf("String obtained on concatenation is \"%s\"\n", w);
getch();
return 0;
}
这看起来不像C++。你的意思是哪种语言? –
^^也许,但有了格式,谁可以告诉? –
我在这里没有看到C++。 – Joel