Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ELIZA TYPE PROGRAM

Posted on 1998-10-31
4
Medium Priority
?
250 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
[X]
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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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 how to use strings and some functions related to them 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.

618 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