如何添加两个不同的数组?

时间:2019-04-01 11:25:07

标签: c

我是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

如果我想显示“彩虹2”而不是“彩虹”或“ 2”,该怎么办

1 个答案:

答案 0 :(得分:1)

您可以使用snprintf函数,该函数可以像printf一样格式化打印,只是目标是字符串而不是stdout:

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