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

📄 file.cpp

📁 数据挖掘中Aprior算法的C++实现
💻 CPP
字号:
#include "file.h"

int FileItemtoNum(const char *datafile){
	STN *stn1,*stn2,*per,*data;
    char line[20*4096];
    int num=0;
    FILE *fp,*fp1,*fp2;
    char *t, *s;
    data = (STN *)new STN;
    data->next=(STN*)NULL;
    data->count=0;
    data->str=(char*)NULL;
    if((fp = fopen(datafile, "rt")) == NULL)
        return 0;
    if((fp1 = fopen("temp.txt", "wt")) == NULL)
        return 0;
    while(fgets(line, 20*4096, fp) != NULL)
    {
        if (strchr(line, ' ') != NULL)
        {
            s = (char *) new char[strlen(line) + 1];
            strcpy(s, line);
			t=strtok(s,"\n");
            if ((t = strtok(s, " ")) == NULL)
            {
                delete s;
                break;
            }
            for(stn1=data;stn1!=NULL;stn1=stn1->next)
                {
				per=NULL;
				if(stn1->str!=NULL)	
                if(strcmp(stn1->str,t)==0)
                    {
                    fprintf(fp1,"%d",stn1->count);
                    break;   
					}
				per=stn1;
				}	
            if(stn1==(STN*)NULL&&t!=NULL)
                {	
                stn2=(STN *)new STN;
                stn2->str=(char *)new char[strlen(t) + 1];
                strcpy(stn2->str,t);
                stn2->next=(STN*)NULL;
                stn2->count=(per->count)+1;
                per->next=stn2;
                fprintf(fp1,"%d",stn2->count);
				}
            for ( t = strtok((char *)NULL, ","); t != NULL; t = strtok((char *)NULL, ","))
            {
            fputc(',',fp1);
            for(stn1=data;stn1!=NULL;stn1=stn1->next)
                {
				per=NULL;
				if(stn1->str!=NULL)
                if(strcmp(stn1->str,t)==0)
                    {
                    fprintf(fp1,"%d",stn1->count);
                    break; 
					}
                per=stn1;
				}		
            if(stn1==(STN*)NULL&&t!=NULL)
                {
				stn2=(STN *)new STN;
                stn2->str=(char *)NULL;
				stn2->str=(char *)new char[strlen(t) + 1];
				strcpy(stn2->str,t);
                stn2->next=(STN*)NULL;
                stn2->count=(per->count)+1;
                per->next=stn2;
                fprintf(fp1,"%d",stn2->count);
				}
            }
        }
    fputc('\n',fp1);
    }
    if((fp2 = fopen("temp2.txt", "wt")) == NULL)
        return 0;
	for(data=data->next;data!=NULL;data=data->next)
	{
		fprintf(fp2,"%s--->%d\n",data->str,data->count);
	}
	fflush(fp1);
    fclose(fp1);
	fflush(fp2);
	fclose(fp2);
	fflush(fp);
    fclose(fp);
		return 1;
}

⌨️ 快捷键说明

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