文档介绍:#include <> #include <> #include <> #include <> //_getcwd(), _chdir() #include <> //_MAX_PATH, system() #include <> //_finddata_t, _findfirst(), _findnext(), _findclose() char vocabulary[1000][20];/* 声明公有二维数组,用来存储分割好的单词*/ /*================= 将要分类的文本分割成单词存储在二维数组 vocabulary 中================*/ //@ 输入参数:要分类的文本//@ 输出参数:该文本中总单词数 int SplitToWord(char text[]) { int i=0; char seps[]=", .\n"; /* 定义单词的分隔符*/ char *substring; /****** 利用分隔符将文本内容分割成单词并存储******/ substring=strtok(text,seps); while(substring!=NULL) { strcpy(vocabulary[i],substring);// 将单词存储到 vocabulary 数组中 substring=strtok(NULL,seps); i++; } return i; // 返回一共多少个单词} /*=============================== 计 算该目录下的文件数================================*/ //@ 输入参数:无//@ 输出参数: 文件数 int CountDirectory() { int count=0; //txt 文件计数器 long hFile; _finddata_t fileinfo; /******** 文件,记录文件数**********/ if ((hFile=_findfirst("*.txt",&fileinfo))!=-1L) { do { count++; } while (_findnext(hFile,&fileinfo) == 0); } return count; } /*=================================== 计 算某类别中∏ P(ai|vj)===================================*/ //@ 输入参数:分类文本中单词数//@ 输出参数:该类别下∏ P(ai|vj) float CalculateWordProbability(int wordCount) { int countSame; // 分类文本中的某单词在所有训练样本中出现次数 int countAll=0; // 训练样本中总单词数 char token; FILE *fp; float wordProbability=1; // 为后面联乘做准备 int i,j; long hFile; _finddata_t fileinfo; for(j=0;j<wordCount;j++)