Hi all, I am experimenting with this program where if you ask the time it tells you the time. I found
a function in the string.h header file which searchs for a sub-string inside a string and returns a pointer to the sub-string if it is found.
At the moment it only works if I type "time" and nothing else however if I type "what is the time" it doesn't work. It also never returns "Invalid Question!".
If there is something I am doing wrong, or if there is a better way to do this, please tell me.
Thanks in advance
CODE
void time ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
string time = (asctime (timeinfo));
cout << "The current time is: " << time <<endl;
}
int main ()
{
char question[500];
char * locate;
cout << "Welcome" << endl;
system("pause");
cout << "Ask a Question:" << endl;
cin >> question;
locate = strstr (question,"time");
//cout << locate;
if (locate != "") time();
else cout << "Invlaid question!";
return 0;
}