I want to make a function in C but clueless what to do I know how to do it with integers but not with characters/strings
printf("\nEnter player %d name: ", i);
scanf ("%s", playername[i]);
This allows me to read name. %d is just a number above
I want to create a function where it generates a random number (I know how to do that) and then print out a greeting message
So something like this
int grmessage;
grmessage = rand () %4;
srand (time(NULL));
if (grmessage == 0)
printf("Welcome to the game, %s!\n" , playername[i]);
else if (grmessage == 1)
printf("Hello %s and welcome!\n" , playername[i]);
else if (grmessage == 2)
printf("%s has joined us! Say hello!\n" , playername[i]);
else if (grmessage == 3)
printf("Pleasure to have you in this game %s!\n" , playername[i]);
else if (grmessage == 4)
printf("Why hello there %s!\n" , playername[i]);
else
printf("Say hello to %s who has entered the game.\n" , playername[i]);
Now can someone tell me how to put the above block of code in a function
So essentially
...
void texter (char a) { my code above }
and then when I call the function again to have it print out the text
printf("\nEnter player %d name: ", i);
scanf ("%s", playername[i]);
texter (playername[i]);
I know I already gave the code literally but just need to fix it and make it work as that's what I would do if it was an integer