Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ELIZA TYPE PROGRAM

Posted on 1998-10-31
4
222 Views
Last Modified: 2010-04-15
PLEASE, I NEED SOME BASIC CODE FOR AN "ELIZA" TYPE PROGRAM WHERE YOU CAN "TALK" WITH THE PROGRAM OF ONLY ONE SUBJECT (USING STRINGS), CAUSE I HAVE PROBLEMS WITH THE USE OF THE STRTOK FUNCTION, THANKS
0
Comment
Question by:jarriaca
  • 2
  • 2
4 Comments
 

Author Comment

by:jarriaca
ID: 1253973
Edited text of question
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 1253974
Here's an excerpt from the MS demo app 'doctor' (part of the sample source code from the MS Platform SDK, available at 'http://www.microsoft.com/msdn/sdk/platform.htm')

If you need the full source code, search MSDN online using the keywords 'doctor rpc' or go directly to 'http://premium.microsoft.com/msdn/library/devprods/vs6/vc++/vcsample/vcsmpdoctor.htm' (or post your email address and i'll send it to you)

/* Add possible substrings to the response string */

void Respond(char *str, char *finalstr)
{
    char copy[STRSIZE];  // copy of the substring to process token at a time
    char *token;
    char *word;
    int index;           // index to substring (string converted to number)
    int len = 0;         // index to output string for sprintf

    while (*str) {

        if (! isdigit(*str))
            len += sprintf(finalstr + len, "%c", *str++);

        else {  // check for pattern number

            index = atoi(str);     // extract pattern number
            while (isdigit(*str))  // skip number in pattern
                str++;

            strcpy(copy, Substring[index]);  // process substring
            token = strtok(copy, " ");       // skip blanks

            while (token) {
                word = token;

                if (! strcmp(token,"I") || ! strcmp(token,"ME"))
                    word = "YOU";
                else if (! strcmp(token,"YOU"))
                    word = "I";
                else if (! strcmp(token,"MY"))
                    word = "YOUR";
                else if (! strcmp(token,"YOUR"))
                    word = "MY";
                else if (! strcmp(token,"MINE"))
                    word = "YOURS";
                else if (! strcmp(token,"YOURS"))
                    word = "MINE";
                else if (! strcmp(token,"MYSELF"))
                    word = "YOURSELF";
                else if (! strcmp(token,"YOURSELF"))
                    word = "MYSELF";
                else if (! strcmp(token,"I'M"))
                    word = "YOU'RE";
                else if (! strcmp(token,"YOU'RE"))
                    word = "I'M";
                else if (! strcmp(token,"AM"))
                    word = "ARE";
                else if (! strcmp(token,"WAS"))
                    word = "WERE";

                len += sprintf(finalstr + len, "%s", word);

                // get next token from Substring
                if ((token = strtok(NULL, " ")) != NULL)
                    len += sprintf(finalstr + len, " ");

            }  // end while token

        }  // end else (if isdigit)

    }  // end while str

    len += sprintf(finalstr + len, "\n");

}  // end function Respond

0
 

Author Comment

by:jarriaca
ID: 1253975
please jkr, send me the complete code at juanparcar@hotmail.com
 thanks a lot , you help me very much
0
 
LVL 86

Expert Comment

by:jkr
ID: 1253976
OK, will send it on monday ;-)
(have to be at the office to do this <s>)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question