数据检索

    xiaoxiao2023-03-24  5

    关于数据的检索—硬盘模式

    #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> // 包含所必需的头文件 char strpath[256]="D:\\大数据相关数据\\数据.txt"; char savepath[256]={0};//定义一个数组保存搜寻的数据 // 开始搜寻数据 void showlist(char str[256]) { sprintf(savepath, "D:\\%s.txt", str);//创建文本 FILE *pf; //文件指针 pf = fopen(strpath, "r"); //读取 FILE *pfw = fopen(savepath, "w");//写入 //判断 if (pf == NULL || pfw == NULL) { printf("文件打开失败"); } else { // feof(pf)到了文件末尾返回1,否则返回0 while (!feof(pf)) //没有找到文件末尾就继续 { char readstr[1024] = { 0 }; fgets(readstr, 1024, pf); //读取一行 char *p = strstr(readstr, str); //字符串查找 if (p != NULL) { puts(readstr); //打印 fputs(readstr, pfw); //写入 } } fclose(pf);//关闭 fclose(pfw); } } void main() { char str[256] = { 0 }; scanf("%s", str); //输入字符串 printf("请输入您要查询的信息:%s\n", str); time_t start, end;//定义时间变量 time(&start);//当前时间 showlist(str);//调用 time(&end); printf("程序用时%f秒\n", difftime(end, start)); system(saepath);//打开输出的信息 system("pause"); }
    转载请注明原文地址: https://ju.6miu.com/read-1201625.html
    最新回复(0)