write me a code in C to make a chat bot
- User
write me a code in C to make a chat bot
Assistant
Here is a basic C code for a chat bot:
#include <stdio.h> #include <string.h> int main() { char name[50]; char botname[50] = "Chatty"; char message[100]; char response[100]; printf("Hello! My name is %s. What's your name? ", botname); gets(name); printf("Hi %s! Nice to meet you. What would you like to chat about?", name); while (1) { gets(message); if (strcmp(message, "bye") == 0) { printf("Goodbye %s! It was nice talking to you.", name); break; } else if (strstr(message, "how are you") != NULL) { strcpy(response, "I'm doing well, thanks for asking! How about yourself?"); } else if (strstr(message, "what's up") != NULL) { strcpy(response, "Not much, just chatting with you!"); } else { strcpy(response, "I apologize, I don't understand. Can you rephrase that?"); } printf("%s: %s\n", botname, response); printf("%s: ", botname); } return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.