I am trying to make a mad libs game but every time I test the first two scanf
functions work, but the fgets
function is not working how it should be.
it keeps printing the same things I want it to but it's showing the mad libs text before the user has a chance to type in the fgets
input
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char color[20];
char COL2[20];
printf("Enter a color: ");
scanf("%s", color);
printf("Enter a another color: ");
scanf("%s", COL2);
printf("Enter a celebrity name: \n");
char celebrity[15];
fgets(celebrity, 15, stdin);
printf("Roses are %s", color);
printf("Violets are %s", COL2);
return 0;
}
CodePudding user response:
fscanf(stdin, "s", celebrity);
It worked on my laptop, so it should be fine. Also fscanf is better and safer usually from what I've heard. Because it checks for end of line.
CodePudding user response:
Mad Libs is a game where you have to fill in the blanks by the part of speech that is asked(Noun, plural noun, Adjective etc.)
CodePudding user response:
Cheetah, here it is
` make -s
./main
Enter a color: red
Enter a another color: blue
Enter a celebrity name:
Roses are red
Violets are blue,
I love`