求助一串代码的意思!
size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);record* find_match(char* input) {
for(int i = 0; i < nKnowledgeBaseSize; ++i) {
if( !stricmp( KnowledgeBase[i].input, input ) )
return &KnowledgeBase[i];
}
return NULL;
}
void chatterbot2()
{
srand((unsigned) time(NULL));
char sInput[20] = {0};
char* sResponse = NULL;
while(1) {
printf("我:");
scanf("%19[^\n]", &sInput);
fflush(stdin);
record* responses = find_match(sInput);
if(sInput == "BYE") {
printf("和你聊天太愉快了,下次再来!\n");
_sleep(1000);
break;
}
else if( !responses ) {
printf("我,我,我不确定我是否能理解你说的是什么 ...\n");
}
else {
int nSelection = rand() % MAX_RESP;
sResponse = responses->responses[nSelection];
printf("%s\n", sResponse);
}
}
}
int main()
{
chatterbot2();
return 0;
}