zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    第三方类AFNetworking(一)
    objective-C nil,Nil,NULL 和NSNull的小结
    DOM解析XML文件
    设置导航栏字体大小,颜色和加粗字体的方法
    数据本地化之沙盒机制
    本地存储Sqlite的用法:
    iOS面试题
    iOS 知识-常用小技巧大杂烩
    怎么升级iOS10教程
    2016WWDC详解
  • 原文地址:https://www.cnblogs.com/whl2012/p/2758822.html
Copyright © 2011-2022 走看看