如何將字符串從數組傳遞到函數? 我想一個字符串,如"Battleship"
傳遞到功能print()
並將其打印"Where would you like to place the Battleship?"
我可以將字符串傳遞給函數嗎?
#include <stdio.h>
void print(char ship_names);
int main (void)
{
int index = 0;
char ships_name[5][21]= { "Aircraft Carrier (5)", "Battleship (4)", "Submarine (3)",
"Cruiser (3)", "Destroyer (2)"};
for(index = 0; index < 5; index++)
print(*ships_name[index]);
return 0;
}
void print(char ship_names)
{
printf("Where would you like to place the %s?\n", ship_names);
}