C 如何添加两个不同的阵列?

C 如何添加两个不同的阵列?,c,C,我是C的新手,设置POS终端,我需要能够将两个字符串数组作为一个数组传递 我已经成功地实现了第一个数组,它工作得很好,现在我想同时通过它们 getListItemPrompt(&promptGames, "Games", "Diamond|Rainbow |Sky |Mercury |Jasper |Gold |Octopus |Silver"); char *gamelist[8]={"Diamond","Rainbow","Sky","Mercury","Jasper","Gold

我是C的新手,设置POS终端,我需要能够将两个字符串数组作为一个数组传递

我已经成功地实现了第一个数组,它工作得很好,现在我想同时通过它们

getListItemPrompt(&promptGames, "Games", "Diamond|Rainbow |Sky |Mercury |Jasper |Gold |Octopus |Silver");

char *gamelist[8]={"Diamond","Rainbow","Sky","Mercury","Jasper","Gold","Octopus","Silver"};

getListItemPrompt(&promptNumber, "NUMBER", "1 |2 |3 |4 |5 |6 |7 |8 |9 ");

char *numberlist[9]= {" 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9"};

strmcpy(gameInfo.option.title, gamelist[2]);
//This displays "Rainbow" which works accurately

strmcpy(gameInfo.option.title, numberlist[2]);
//This displays " 2" which works accurately

如果我想显示例如“Rainbow 2”而不是仅仅显示“Rainbow”或“2”

你可以使用
snprintf
功能,该功能可以像
printf
一样进行格式化打印,但目标是字符串而不是标准输出:

snprintf(gameInfo.option.title, sizeof(gameInfo.option.title), "%s %s",
        gamelist[2], numberlist[2]);

如何使用例如
snprintf
?什么是
strmcpy
?strmcpy是strncpyy的一个宏扩展你不是在“添加数组”,你是在“连接字符串”,中间有空格要记住:
sizeof(gameInfo.option.title)
只有在
gameInfo.option.title
声明为
char[]
,如果声明为
char*
,则不会。好的,谢谢。我使用此信息取得了进展并解决了问题。