0

我想将两个字符串数组合并为一个数组:

数组 1:

firstnames[NUMBER_NAMES][LEN_NAME] = {"luca","tomas"} 

和数组 2:

secondname[NUMBER_NAMES][LEN_NAMES] = {"goirgi", "edison"}

我想把它们放在一个数组中,名字和姓氏可以在一起

4

1 回答 1

0

First, include :

#include <string.h>

Now, let the string be stored in names[NUMBER_NAMES][LEN_NAMES]

char name[sNUMBER_NAMES][LEN_NAMES];

Finally, a for loop for each element in the array:

for(i=0;i<NUMBER_NAMES;i++)
 { strcpy(names[i],firstnames[i]); //To initialize ith names element with first name
   strcat(names[i])," ");          //To concatanate a space between the 2 names   
   strcat(names[i]),lastnames[i]); //Concatanate the last name to the firstname+ space string
}
于 2013-06-23T05:12:03.347 回答