[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ELIZA TYPE PROGRAM

Posted on 1998-10-31
4
Medium Priority
?
254 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 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