我想逐個字母地拼接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