I'm trying to create a little program that asks the user to enter two phrases. After entering two phrases, I display the phrases back to the user. Then I put both phrases into one variable, which I then display back a third time using one variable.
Next, I am trying to attempt to pick a letter at random from the two phrases and display the letter back to the user.
I've been doing some research online to see how people pick letters at random, but I haven't really seen anything other than picking words at random, but didn't really see how this could be applied to my own program.
thanks in advance.
P.S I'm noticing that when displaying the two phrases together, the second one is on a newline. Can anyone explain why that happens and how to get rid of it too? thanks
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
int main()
{
srand(time(NULL));
char phrase1[100], phrase2[100];
printf("Please enter your first phrase\t");
fgets(phrase1, 100, stdin);
printf("Please enter your second phrase\t");
fgets(phrase2, 100, stdin);
printf("The first phrase you entered was: %s", phrase1);
printf("The second phrase you entered was: %s", phrase2);
strcat(phrase1, phrase2);
phrase1[strlen(phrase1)-1] = ' ';
printf("Both phrases put together in one sentence is: %s", phrase1);
return 0;
}