How can I pass a string from an array into a function?
I want to pass a string such as "Battleship"
into the function print()
and have it 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);
}