View Poll Results: Good Idea?

Voters
3. You may not vote on this poll
  • Yes

    3 100.00%
  • No

    0 0%

Thread: AI Chatbox

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question AI Chatbox

    I'm making this chatbox project called The Not A Friend Project... Anyway, this project is based on a former chat box, hal. I don't remember the creater, he was on this board a while back and posted his creation. Although, he didn't give source code, so I'm starting from scratch. Here's the source code:

    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <fstream.h>
    #include <string.h>
    #include <conio.h>
    char blank[]=" ";
    
    class mainbot
    {
    	public:
    		mainbot::mainbot();
    		~mainbot();
    		int userintf();
    		int checkinput();
    		int checkoutput();
    	private:
    		char inp[75];
    		int inpno;
    		char responce[75];
    		char inchk[75];
    		int inchkcnt;
    		char str;
    };
    mainbot::mainbot()
    {
    }
    mainbot::~mainbot()
    {
    }
    int mainbot::userintf()
    {	
    	cin.getline(inp,75);
    	checkinput();
    	checkoutput();
    	cout << responce;
    	return 0;
    }
    int mainbot::checkinput()
    {
    	ifstream input("input.txt");
    	input >> str;
    	inchkcnt=1;
    	while(strcmp(inchk,blank)||!strcmp(inchk,inp))
    	{
    		strtok(str, inchkcnt);
    		inchk=strtok(NULL, inchkcnt);
    		inchkcnt++;
    	}
    	if(!strcmp(inchk,blank))
    	{
    		cout << "I don't understand." << endl;
    	}
    	else
    	{
    		input.close();
    		checkoutput();
    	}
    }
    int mainbot::checkoutput()
    {
    	ifstream output("output.txt");
    	output >> str;
    	strtok(str, inchknt);
    	responce=strtok(NULL, inchknt);
    	output.close();
    }
    
    
    int main()
    {
    	mainbot interf;
    	interf.userintf();
    	return 0;
    }
    I've gone through debugging for a while bringing 14 errors down to three:

    Code:
    E:\Programs\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(45) : error C2664: 'strtok' : cannot convert parameter 1 from 'char' to 'char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    E:\Programs\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(46) : error C2664: 'strtok' : cannot convert parameter 2 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    E:\Programs\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(63) : error C2065: 'inchknt' : undeclared identifier
    They seemed to have either a problem with strtok or with the variables they are taking in. Does anybody know how to solve this? If you see any other problems I may not have picked up, could you post the cures? Thanks.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    inchknt

    i think should be inchkcnt
    now u got 2 errors

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Salem, does your code work with these adjustments? Because mine doesn't.

  4. #4
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Latest code
    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <fstream.h>
    #include <string.h>
    #include <conio.h>
    char blank[]=" ";
    
    class mainbot
    {
    	public:
    		mainbot::mainbot();
    		~mainbot();
    		int userintf();
    		int checkinput();
    		int checkoutput();
    	private:
    		char inp[75];
    		int inpno;
    		char responce[75];
    		char inchk[75];
    		int inchkcnt;
    		char str[500];
    };
    mainbot::mainbot()
    {
    }
    mainbot::~mainbot()
    {
    }
    int mainbot::userintf()
    {	
    	cin.getline(inp,75);
    	checkinput();
    	checkoutput();
    	cout << responce;
    	return 0;
    }
    int mainbot::checkinput()
    {
    	ifstream input("input.txt");
    	input >> str;
    	inchkcnt=1;
    	while(strcmp(inchk,blank)||!strcmp(inchk,inp))
    	{
    		strtok(str, inchkcnt);
    		cout << "hello";
    		strcpy( inchk, strtok(NULL, inchkcnt) );
    		inchkcnt++;
    	}
    	if(!strcmp(inchk,blank))
    	{
    		cout << "I don't understand." << endl;
    	}
    	else
    	{
    		input.close();
    		checkoutput();
    	}
    }
    int mainbot::checkoutput()
    {
    	ifstream output("output.txt");
    	output >> str;
    	strtok(str, inchkcnt);
    	strcpy( responce, strtok(NULL, inchkcnt) );
    	output.close();
    }
    
    
    int main()
    {
    	mainbot interf;
    	interf.userintf();
    	return 0;
    }
    Latest Bugs:
    Code:
    E:\PROGRAMS\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(45) : error C2664: 'strtok' : cannot convert parameter 2 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    E:\PROGRAMS\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(46) : error C2664: 'strtok' : cannot convert parameter 2 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    E:\PROGRAMS\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(63) : error C2664: 'strtok' : cannot convert parameter 2 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    E:\PROGRAMS\Projects\Tests\Chat Bot\notafriend\nofsource.cpp(64) : error C2664: 'strtok' : cannot convert parameter 2 from 'int' to 'const char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Your compiler is telling you what the problem is. The second parameter to strtok() is expecting a constant character pointer, you are giving it an int!

    Example from MSDN...

    Code:
    /* STRTOK.C: In this program, a loop uses strtok
     * to print all the tokens (separated by commas
     * or blanks) in the string named "string".
     */
    
    #include <string.h>
    #include <stdio.h>
    
    char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;
    
    void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
    *** EDIT ***

    Sorry salem - overlap!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ..

    Ok, I've found an in-program error that I narrowed down to here:
    Code:
    strcpy( inchk, strtok(NULL, blank) );
    Salem, I'm using strtok to scan for anything after the checked number. Shouldn't that work? I couldn't think of another way.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    I would say in 9 out of 10 instances strtok is the devil. It isn't thread safe and it modifies your variables. Ick! Try strstr or strchr.

    http://www.freebsd.org/cgi/man.cgi?q...SD+5.0-current
    http://www.freebsd.org/cgi/man.cgi?q...SD+5.0-current

    On a side note, now comlex of an AI are you planning on making? Making a good AI Chatbot is a pretty complex thing. Do you have a plan for parsing input?

    Do you mean chatbot or chatbox? And what is a chatbox?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple space combat AI
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 01-06-2009, 12:54 AM
  2. chess ai contest
    By Raven Arkadon in forum Contests Board
    Replies: 7
    Last Post: 07-09-2005, 06:38 AM
  3. AI Contest Proposal
    By MadCow257 in forum Contests Board
    Replies: 4
    Last Post: 03-13-2005, 03:27 PM
  4. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 10:35 AM
  5. Technique of all board-like games?
    By Nutshell in forum Game Programming
    Replies: 28
    Last Post: 04-24-2002, 08:19 AM