Solved

ELIZA TYPE PROGRAM

Posted on 1998-10-31
4
196 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now