If you want to create a chatbot/auto replay system use the c program just use this code:
Copy below code and save use extension .c. example, filename.c.
#include <stdio.h> #include <string.h> int main() { char question[100]; printf("Hello sir, \nWelcome to our Caffe chatbox. How can we help you?\n"); printf("---------------------------------------------------\n"); START: printf("\nEnter Your Question:\n"); gets(question); if(strcmp(question,"hi") == 0 || strcmp(question,"hello") == 0) { printf("Hello sir, How can we help you?\n"); } else if(strcmp(question,"how are you") == 0 || strcmp(question,"how are you?") == 0) { printf("I am fine! you?\n"); } else if(strcmp(question,"bye") == 0) { goto EXIT; } else { printf("Sorry sir. I can't understand what you want to say.\n"); printf("do you have any question?\n"); gets(question); if(strcmp(question,"yes") == 0 ) { goto START; } else if(strcmp(question,"no") == 0) { goto EXIT; } } goto START; EXIT: printf("Thank you so much for contact us. Bye\n\n"); return 0; }
I am using if-else and goto conditions. also use strcmp() function to compare two strings.
C program auto replay chatbot Screen Shoot:
You can also use this code to create chatbot in c program:
#include <stdio.h> #include <string.h> int main() { char a[100], b[100]; char temp[10]="hi",temp2[10] = "hello"; printf("Enter your question.\n"); gets(a); if (strcmp(a,temp) == 0) printf("Hello sir. Welcome to our Caffe chatbox. How can we help you?\n"); else printf("Sorry sir. It's not available in our service.\n"); return 0; }
In this code, I am using an array for listing questions.
I hope this code helps you to create a chatbot or auto replay system use c program.