home *** CD-ROM | disk | FTP | other *** search
/ Languages Around the World / LanguageWorld.iso / language / chinese / ec_dict / crtidx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-31  |  766 b   |  40 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. main()
  5. {
  6.   FILE    *dat,*idx;
  7.   char    buf[255];
  8.   char  *t;
  9.   int    n=255,j, buflen;
  10.   long    i,pos;
  11.  
  12.  
  13.   dat = fopen("tdic.dic","r");
  14.   idx = fopen("tdic.idx","wb");
  15.   fwrite(&j,1,2,idx);    /* number of index records */
  16.   fgets(buf,n,dat);
  17.   pos = strlen(buf);
  18.   fgets(buf,n,dat);
  19.   i = 1;
  20.   do {
  21.     buflen = strlen(buf);
  22.     if ((i % 256) == 1) {
  23.       for(j=0;buf[j] != '\t';j++);
  24.       for(;j<25;j++)
  25.       buf[j] = 0;
  26.       strlwr(buf);
  27.       fwrite(buf,1,25,idx);
  28.       fwrite(&pos,1,4,idx);
  29.     }
  30.     pos += buflen;
  31.     if ((t = fgets(buf,n,dat)) != NULL)
  32.       i++;
  33.   } while( t != NULL);
  34.   j = i/256 + 1;
  35.   fseek(idx, 0,SEEK_SET);    /* rewrite number of index records */
  36.   fwrite(&j,1,2,idx);
  37.   fclose(idx);
  38.   fclose(dat);
  39. }
  40.