1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#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;
}
|