运行出错 各位帮忙检查下错误
#include<iostream.h> #include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
struct KeyWord{
char Keyword[20];
int count;
};
KeyWord KeywordTable[]=
{
{"else",0},{"for",0},{"if",0},{"include",0},{"while",0}
};
int SeqSearch(KeyWord *tab,int n,char *word)
{
int i;
for(i=0;i<n;i++,tab++)
if(strcmp(word,tab->Keyword)==0)
return i;
return -1;
}
int Getword(ifstream &fin,char w[])
{
char c;
int i=0;
while(fin.get(c)&&!isalpha(c));
if(fin.eof())
return 0;
w[i++]=c;
while(fin.get(c)&&(isalpha(c)||isdigit(c)))
w[i++]=c;
w[i]='\0';
return 1;
}
void main(void)
{
const int MAXWORD=50;
const int NKEYWORDS=sizeof(KeywordTable)/sizeof(KeyWord);
int n;
char word[MAXWORD],c;
ifstream fin;
fin.open("prg2_5.cpp",ios::in | ios::nocreate);/prg2_5.cpp就是统计本文件
if(!fin)
{
cerr<<"Could not open file'prg2_5.cpp'"<<endl;
exit(1);
}
while(Getword(fin,word))
if((n=SeqSearch(KeywordTable,NKEYWORDS,word))!=-1)
KeywordTable[n].count++;
for(n=0;n<NKEYWORDS;n++)
if(KeywordTable[n].count>0)
{
cout<<KeywordTable[n].count;
cout<<" "<<KeywordTable[n].Keyword<<endl;
}
fin.close();
getch();
}