1. main.c
//#include "createsort.h" //#include "createindex.h" #include "binsearch.h" void initall() { strcpy(filepath, "Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\1E~001OK.txt"); strcpy(sortpath, "Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\1E~001sort.txt"); strcpy(indexpath, "Z:\I\尹成清华终极版C语言视频源码文档20150131\大数据相关数据\1E~001index.txt"); } void main() { initall(); /*initmem(); sort(); writetofile();*/ //init(); while (1) { char str[256] = { 0 }; scanf("%s", str); binsearch(str); } system("pause"); }
2.index.h
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define N 10000000
struct index
{
int *pindex;
int length;
};
char **g_pp;//保存指针数组
char filepath[256];
char sortpath[256];
char indexpath[256];
struct index allindex;//索引
int getN();//函数声明
void eatg(char *str);
void eatN(char *str);
2.index.c
#include"index.h"
char **g_pp = NULL;//保存指针数组
char filepath[256] = { 0 };
char sortpath[256] = { 0 };
char indexpath[256] = { 0 };
struct index allindex = { 0 };//索引
int getN()
{
FILE *pf = fopen("file.txt", "r");
if (pf == NULL)
{
return -1;
}
else
{
int i = 0;
while (!feof(pf))
{
char str[50] = { 0 };
fgets(str, 50, pf);//读取
i++;
}
fclose(pf);
return i;
}
}
void eatg(char *str)
{
while (*str != '