我想将两个字符串数组合并为一个数组:
数组1:
firstnames[NUMBER_NAMES][LEN_NAME] = {"luca","tomas"}
和数组 2:
secondname[NUMBER_NAMES][LEN_NAMES] = {"goirgi", "edison"}
我想将它们放入一个数组中,其中名字和姓氏可以在一起
最佳答案
首先,包括:
#include <string.h>
现在,让字符串存储在名称[NUMBER_NAMES][LEN_NAMES]中
char name[sNUMBER_NAMES][LEN_NAMES];
最后,对数组中的每个元素进行 for 循环:
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
}
关于c - 如何在C编程中将两个二维字符串数组合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17257276/