| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:运行出错 各位帮忙检查下错误
只看楼主 加入收藏
mlangel
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-17
收藏
 问题点数:0 回复次数:0 
运行出错 各位帮忙检查下错误
#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();     
  }
搜索更多相关主题的帖子: 错误 
2008-11-18 10:20
快速回复:运行出错 各位帮忙检查下错误
数据加载中...
 
   



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

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