是否可以通过使用%c
来包含变量,例如当您将字符串保存到数组中时?
char *MainMenuNames[] = { "%c - Move Left", "%c - Move Right","%c - Move Up","%c - Move Down","%c - Back","%c - Confirm","%c - Show Stats","%c - Show Inventory","%c - Show Legend","%c - Show Controls"};
当我有这样的事情时,是否可以在%c
?
答案 0 :(得分:2)
您可以使用数组元素作为参数来格式化printf()
char *commands = "lrudbcsiln";
for (int i; i < strlen(commands); i++) {
printf(MainMenuNames[i], commands[i]);
putchar('\n');
}