I am brand new to this, I'm just starting with like no experience. I know this is going to seem a bit childish, but this is the code I'm working on. I thought it'd be hilarious if I made something that resembled a chatbot since so far I've learned the printf and scanf functions, as well as variables in my programming class. I saw online that using %[^\n]s causes scanf to read the user input up to the next line and store it in the variable I set. Problem is, it works fine for the first input, then prints the rest of the text without prompting another user input. Any ideas what I need to change in this code? (also apologies if I formatted this post wrong, I'm not familiar with this sub)
#include<stdio.h>
int main()
{
char ans1\[100\];
char ans2\[100\];
char ans3\[100\];
setbuf(stdout,NULL);
printf("Hello! I am ChatECK!\\nWhat is your name? ");
scanf("%\[\^\\n\]s", ans1);
printf("LMAO %s DEEZ NUTS!\\n", ans1);
printf("Ask me anything! ");
scanf("%\[\^\\n\]s", ans2);
printf("%s DEEZ NUTS!\\n", ans2);
printf("Tell me something about yourself: ");
scanf("%\[\^\\n\]s", ans3);
printf("%s DEEZ NUTS LOL!\\n", ans3);
printf("Thanks for chatting with me!");
return 0;
}
The output ends up with this after I enter my name:
Hello! I am ChatECK!
What is your name? Eliminator152
LMAO Eliminator152 DEEZ NUTS!
Ask me anything! ��a DEEZ NUTS!
Tell me something about yourself: DEEZ NUTS LOL!
Thanks for chatting with me!