请求高手解答这个程序错在哪里?
/*编写一个程序,从键盘上读取任意长度的一段文本,确定该文本中每个单词出现的频率 */#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define TEXTLEN 10000
#define BUFFERSIZE 100
#define MAXWORDS 500
#define WORDLEN 15
int main(void)
{
char text[TEXTLEN+1];
char buffer[BUFFERSIZE];
char endstr[]="*\n";
const char space=' ';
const char quote='\'';
char words[MAXWORDS][WORDLEN+1];
int nword[MAXWORDS];
char word[WORDLEN+1];
int wordlen=0;
int wordcount=0;
printf("Enter txtx on an arbitrary number of lines.");
printf("\nEnter a line containing just an asterisk to end input:\n\n");
while(true)
{
if(!strcmp(fgets(buffer,BUFFERSIZE,stdin),endstr))
break;
if(strlen(text)+strlen(buffer)+1>TEXTLEN)
{
printf("最大文本容量超出.终止程序!");
return 1;
}
strcat(text,buffer);
}
for(int i=0;i<strlen(text);i++)
{
if(text[i]==quote||isalnum(text[i]))
continue;
text[i]=space;
}
int index=0;
while(true)
{
while(text[index]==space)
++index;
if(text[index]=='\0')
break;
wordlen=0;
while(text[index]==quote||isalpha(text[index]))
{
if(wordlen==WORDLEN)
{
printf("最大文本容量超出.终止程序!");
return 1;
}
word[wordlen++]=tolower(text[index++]);
}
word[wordlen]='\0';
bool isnew=true;
for(int i=0;i<wordcount;i++)
if(strcmp(word,words[i])==0)
{
++nword[i];
isnew=false;
break;
}
if(isnew)
{
if(wordcount>=MAXWORDS)
{
printf("\n最大文本容量超出.终止程序!");
return 1;
}
strcpy(words[wordcount],word);
nword[wordcount++]=1;
}
}
for(int i=0;i<wordcount;i++)
{
if(!(i%3))
printf("\n");
printf("%-15s%5d",words[i],nword[i]);
}
return 0;
}
--------------------------------------------------------------------------------------
按道理最后的输出应该是:
Today is sunday,Tomorrow is monday.
Today 1
is 2
sunday 1
Tomorrow 1
monday 1
这样才对 。。可是我运行之后不管怎么输入 都是显示printf("最大文本容量超出.终止程序!");这个错误信息提示.
请问有高手知道这个程序究竟哪里错了么!?万分感谢.