Here is my code, I am trying to make a smaller version of a chatterbot like Eliza. Anyways here it is.
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <string>
#include <windows.h>
#include <fstream>
#include <tchar.h>
// a few global variables
char str[50]; // this one is for the responses, the 50 is a random number, needed something big
int redo; // for restarting the speech thing
using namespace std;
void open_Something()
{
cout << "Enter something to open: ";
char way[50];
cin.getline (way,50);
char *path = way;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
path, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
int main()
{
do
{
string resp[5] = {
"Got anything else to say?",
"That is it, nothing else?",
"...Anything else",
"So, what's up?",
"Talk to me",
};
// number generator
int which_Num;
unsigned seed = time(0);
srand(seed);
which_Num = rand() % 5;
cout << resp[which_Num];
cin.getline (str,50);
char * pch;
pch = strstr (str,"open");
if (pch != NULL)
{
open_Something();
}
char * pch1;
pch = strstr(str,"what, is, your, name,");
if (pch1 != NULL)
{
cout << "My name, you say\n"
<< "It is Jubajee\n"
<< "Cool eh?\n";
redo = 1;
}
char * pch2;
pch = strstr(str,"are you smart, are you intelligent, are you dumb");
if (pch2 != NULL)
{
cout << "What kind of a question is that\n"
<< "I am talking to you aren't I\n"
<< "btw I am smart okay?\n";
redo = 1;
}
//the bottom curly brace is for the do-while loop
}while (redo == 1);
system("PAUSE");
return 0;
}
Okay, the problem is that I can't get it to choose one response. Every time I write one of the keywords all of what is in the if loops appears.
I can't get it to single out one response and then go back to the listing one of the responses in string resp.
Any suggestions on the code would be helpful. Thanks in advance.