| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2959 人关注过本帖
标题:C语言问题求助,qq机器人编写,帮忙看看错误。
只看楼主 加入收藏
河北沧州黄骅
Rank: 1
等 级:新手上路
帖 子:19
专家分:3
注 册:2015-10-18
结帖率:16.67%
收藏
 问题点数:0 回复次数:2 
C语言问题求助,qq机器人编写,帮忙看看错误。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
//一个机器人及基本例子
void chatterbot1()
{
    char *Response[]={"我听到了!",
                      "你是在和我说话。",
                      "继续说,我在听。",
                      "哈哈,真是非常有趣的谈话。",
                      "后来呢?"
};
srand((unsigned) time(NULL));
char sInput[5] = {0};
char *sResponse = NULL;
while(1){
    printf(">");
    scanf("%4s",&sInput);
    fflush(stdin);
    if(sInput[0] == 0x71 || sInput[0] == 0x51){
        printf("和你聊天真的很愉快,下次再见。\n");
        _sleep(1000);
        break;
    }
    int nSelection = rand() % 5;
    sResponse = Response[nSelection];
    printf("%s\n", sResponse);
    }
}
const int MAX_RESP = 3;
typedef struct {
    char *input;
    char *responses[MAX_RESP];
    }record;
    record  KnowledgeBase[] = {
    {"WHAT IS YOUR NAME",
     {"嗯,我的名字叫瞎聊。",
      "你可以叫我公主...,是啊,我是大小姐啊。",
      "为什么你想知道我的名字?下一步是要交换qq号吗?"}
      },
      {
          "HI",
          {
              "哈哈,好啊!",
              "你是谁?",
              "奥,你好!"
          }
      },
      {
          "HOW ARE YOU",
          {
              "我干得不坏!"
              "你干得怎么样?"
              "为什么你会想知道我是怎样做到的?"
          }
      },
      {
          "WHO ARE YOU",
          {
              "我尼玛就是个程序啊。",
              "表说,我知道你知道我是谁。",
              "为什么还问?"
          }
      },
      {
          "ARE YOU INTELLIGENT",
          {
              "是的,当然是的。",
              "你是怎么想的?",
              "哈哈,事实上我确实很聪明。"
          }
      },
      {
          "ARE YOU REAL",
          {
              "这对你真的是个问题吗?",
              "啥意思啊?你?",
              "我尽量让我看起来像个真正的人类。"
          }
      };
      size_t nKnowlegeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);
      record *find_match(char *input){
          for(int i=0; i < nKnowledgeBaseSize;  ++i){
            if( !stricmp( KnowledgeBase[i].input, input))
                return &KnowledgeBase[i];
          }
          return NULL;
      }
      void chatterbot2()
      {
          srand((unsigned) time(NULL));

          char sInput[20] = {0};
          char *sResponse = NULL;

          while(1){
            printf(">");
            scanf("%19[\n]", &sInput);
            fflush(stdin);

            record *responses = find_match(sInput);
            if(sInput == "BYE"){
                printf("和你聊天太愉快了,下次再来!\n");
                _sleep(1000);
                break;
            }
            else if( !responses ){
                printf("我,我,我不确定我是否能理解你说的是什么...\n");
            }
            else {
                int nSelection = rand() % MAX_RESP;
                sResponse = responses->responses[nSelection];
                printf("%s\n", sResponse);
            }
          }

      }
      int main()
      {
          chatterbot1();
          chatterbot2();
          return 0;
      }
E:\新建文件夹 (2)\qq机器人\main.c|34|error: variably modified 'responses' at file scope|
E:\新建文件夹 (2)\qq机器人\main.c|84|error: 'nKnowledgeBaseSize' undeclared (first use in this function)|
搜索更多相关主题的帖子: include 机器人 C语言 
2016-01-01 14:08
zmbilx
Rank: 2
等 级:论坛游民
帖 子:22
专家分:80
注 册:2015-7-18
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
//一个机器人及基本例子

#define MAX_RESP 3

typedef struct  A {
    char* input;
    char* responses[MAX_RESP];
}record;

record  KnowledgeBase[] = 
{
    {
        "WHAT IS YOUR NAME",
        {
        "嗯,我的名字叫瞎聊。",
        "你可以叫我公主...,是啊,我是大小姐啊。",
        "为什么你想知道我的名字?下一步是要交换qq号吗?"
        }
    },

    {
        "HI",
        {
                "哈哈,好啊!",
                "你是谁?",
                "奥,你好!"
        }
    },

    {
        "HOW ARE YOU",
        {
            "我干得不坏!"
            "你干得怎么样?"
            "为什么你会想知道我是怎样做到的?"
        }
    },

    {
        "WHO ARE YOU",
        {
            "我尼玛就是个程序啊。",
            "表说,我知道你知道我是谁。",
            "为什么还问?"
        }
    },
        
    {
        "ARE YOU INTELLIGENT",
        {
            "是的,当然是的。",
            "你是怎么想的?",
            "哈哈,事实上我确实很聪明。"
        }
    },

    {
        "ARE YOU REAL",
        {
            "这对你真的是个问题吗?",
            "啥意思啊?你?",
            "我尽量让我看起来像个真正的人类。"
        }
    }
};
size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);

void chatterbot1()
{
    char *Response[]={"我听到了!",
        "你是在和我说话。",
        "继续说,我在听。",
        "哈哈,真是非常有趣的谈话。",
        "后来呢?"
    };
    char sInput[5] = {0};
    char *sResponse = NULL;
    int nSelection;
    srand((unsigned) time(NULL));

    while(1)
    {
        printf(">");
        scanf("%4s",&sInput);
        fflush(stdin);
        if(sInput[0] == 0x71 || sInput[0] == 0x51){
            printf("和你聊天真的很愉快,下次再见。\n");
            _sleep(1000);
            break;
        }
        nSelection = rand() % 5;
        sResponse = Response[nSelection];
        printf("%s\n", sResponse);
    }
}

record *find_match(char *input)
{
    unsigned int i;
    for(i=0; i<nKnowledgeBaseSize; ++i)
    {
        if( !stricmp( KnowledgeBase[i].input, input))
            return &KnowledgeBase[i];
    }
    return NULL;
}
void chatterbot2()
{
    char sInput[20] = {0};
    char *sResponse = NULL;
    record *responses;
    srand((unsigned) time(NULL));

    while(1){
        printf(">");
        scanf("%19[^\n]", sInput);
        fflush(stdin);
        
        responses = find_match(sInput);
        if(!strcmp("BYE", sInput)){
            printf("和你聊天太愉快了,下次再来!\n");
            _sleep(1000);
            break;
        }
        else if( !responses ){
            printf("我,我,我不确定我是否能理解你说的是什么...\n");
        }
        else {
            int nSelection = rand() % MAX_RESP;
            sResponse = responses->responses[nSelection];
            printf("%s\n", sResponse);
        }
    }
    
}
int main()
{
    chatterbot1();
    chatterbot2();
    return 0;
}

VC++6.0 测试
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2016-2-10 11:28编辑过]


每天OJ一道题,快快乐乐过大年
2016-02-10 11:27
荀减一
Rank: 1
等 级:新手上路
帖 子:19
专家分:2
注 册:2016-2-27
收藏
得分:0 
楼主是黄骅的?
2016-05-09 15:01
快速回复:C语言问题求助,qq机器人编写,帮忙看看错误。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022071 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved