• test_2012117 whl


    1、建立索引

    BuildIndex.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    #define random(x) (rand()%100)
    
    #define NULL 0
    #define Att_Order 3    //属性个数
    #define Att_Length 10   //属性长度
    #define Path_Length 20    //路径长度
    struct Index
    {
        char attribute[Att_Order][Att_Length];
        char path[Path_Length];
    };
    void ReadIndex(int start,int end)
    {
        FILE *idxfp;
        if ((idxfp = fopen("whl.txt","r")) == NULL)
        {
            printf("Cannot open file");
            exit(0);
        }
    
        struct Index *context;
        context = (struct Index *)malloc(sizeof(struct Index));
    
        int j;
        for (j=start; j<=end; j++)
        {
            fseek(idxfp,j*sizeof(struct Index),SEEK_SET);
            fread(context,sizeof(struct Index),1,idxfp);
            int i;
            for (i=0; i<Att_Order; i++)
            {
                printf("%s ",context->attribute[i]);
            }
            printf("%s\n",context->path);
        }
        free(context);
        fclose(idxfp);
    }
    void WriteIndex(int count)
    {
        FILE *idxfp;
        if ((idxfp = fopen("whl.txt","w")) == NULL)
        {
            printf("Cannot open file");
            exit(0);
        }
    
        struct Index *context;
        context = (struct Index *)malloc(sizeof(struct Index));
    
        char temp[10];
        int j;
        for (j=0; j<count;j++)
        {
            int k;
            int i;
            for (i=0; i<Att_Order; i++)
            {
                k=random(1000);
                sprintf(temp,"%d",k);
                strcpy(context->attribute[i],temp);
                printf("%s ",context->attribute[i]);
            }
            strcpy(context->path,"c:\\whl");
            printf("%s\n",context->path);
    
            //fseek(idxfp,0l,SEEK_END);
            fwrite(context,sizeof(struct Index),1,idxfp);
        }
        fclose(idxfp);
    }
    int main()
    {
        int i;
        WriteIndex(100);
        for(i=0; i<100; i++)
        {
            printf("第%d条记录读出:",i+1);
            ReadIndex(i,i);
        }
    
        system("pause");
        return 0;
    }
  • 相关阅读:
    服务端跳转和客户端跳转的区别
    jsp:include标签与include指令的区别
    jsp错误页不跳转显示500
    使用Cookie进行会话管理
    深入理解重定向和转发
    appium环境搭建(二)----搭建android开发环境
    appium环境搭建(一)----安装appium
    Fiddler实现移动端手机抓包
    黑盒测试人员必备技能
    SVN服务器搭建
  • 原文地址:https://www.cnblogs.com/whl2012/p/2758822.html
Copyright © 2020-2023  润新知