HTMLify
chatbot.c
Views: 11 | Author: abh
#include <stdlib.h>
#include "chatbot.h"
char *ChatBot_chat(ChatBot *chatbot, char *message) {
if (message == NULL || message[0] == '\0') return NULL;
ChatMsg usermsg = { chatbot->name, message, SEND };
char *response = chatbot->chat(message);
ChatMsg botmsg = { chatbot->name, response, RECEIVE };
chatbot->messages = realloc(chatbot->messages, (chatbot->msgcount+2)*sizeof(ChatMsg));
chatbot->messages[chatbot->msgcount] = usermsg;
chatbot->messages[chatbot->msgcount+1] = botmsg;
chatbot->msgcount += 2;
return response;
}