c++ 统计关键词个数

来源:百度知道 编辑:UC知道 时间:2024/05/31 09:56:52
用c++写一个程序,统计文本文件中关键词(由用户输入或从另一个文本中读取)。
请大家帮忙。谢谢!
就像百度搜索引擎一样,输入“端午节”,统计文本中“端午节”出现的次数。

#include <stdio.h>
#include <string.h>

int Match(const char *key, const char *data, int len)
{
for (int i=1; i<len; i++)
{
if (*(key + i) != *(data+i))
{
return 0;
}
}
return 1;
}

void main()
{
char *pchKeyword = "and";
char *pchData = "red high heels\
is the way i feels\
got the sways and reels\
going home\
red high heels\
and the church bells peal\
cross the snowy fields\
going home\
i walk down these aisles\
nobody's here-just me\
and the birds in the belfry\
murmuring murmuring\
i took all your letters\
";
char *pchCurPos = pchData;
int iKeyLen = strlen(pchKeyword);
int iDataLen = strlen(pchData);
int iMatchNum = 0;

for (int i=0; i<iDataLen-iKeyLen; i++)