数据检索

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

#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");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值