⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text.cpp.bak

📁 根据一个停用词表
💻 BAK
字号:
#include<stdio.h>
#include<iostream.h>
#include<string>
#include <fstream >
#include<process.h>
using  namespace std;
main()
{
	FILE *fp;//打开一个文件
	int i=0,j=0,count=0;
	char ch;
	char *infile;//申请内存变量
	infile = new char[1000];
    memset(infile,0,1000);//总的作用:将已开辟内存空间 infile 的首 1000 个字节的值设为值 0
	string stop[100],str;
	


	
	char rdBuff[100];
	

	if((fp=fopen("D:\\t.txt","r+"))==NULL)
	{printf("can not open file!");
	 exit(0);
	}


//将停用词表存放在stop[] 中
 // while( !feof(fp) )
	while( fgets(rdBuff,100,fp)!=NULL )
	{
		 stop[count] = rdBuff;
	 
		 int m =  stop[i].find("\n");//原因:读入了换行。
		
		 if(m != string::npos) {
			cout<<"读入了换行符号!"<<endl;
		 }

		 /*去掉换行符,换行符在stop[i]的末尾!*/
		 stop[i].substr(0,(stop[i].length() - 1));
		 
		 
		 count++;
		 printf("%s\n", stop[count - 1].c_str() );//在要求C风格字符串的地方不可直接使用标准库 string 类型对象,返回首地址

	}

//把要处理的字符串,以单个字符的形式读到一个char*指向的空间里
   printf("请输入要处理的字符串:");
   ch=getchar();
   int pos = 0;
   while(('A'<=ch&&ch<='Z')||('a'<=ch&&ch<='z'))
   {  
      infile[pos]=ch;
	  pos++;
	  ch=getchar();
   }
   infile[pos]='\0';
   printf("%s\n",infile);//查看是否已经把字符串读入到char*指向的空间里
  
  // 比较
   int k=1;
    cout<<stop[3].c_str() <<endl;
   for(j=0;j<count;j++)
   { 
	 //  int len = strlen(infile);//含有换行。所以去掉换行,就通过了。
	//	int m = stop[j].find(infile);
	//	string str_test = infile;
	 //  int len_stop = strlen(stop[j].c_str());
     //  int k = stop[j].compare(str_test);//调试可以得到 k = 1;所以应该是stop[j]和infile中
	 if(stop[j].compare(infile)==0)
	 { 
		 k=0;
		 printf("该词是停用词!");
	     break;
	 }

   }
  if(k==1) 
  { printf("该词不是停用词!");
 
  }
    fclose(fp);
	delete[] infile;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -