关于数据的检索—硬盘模式
#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
{
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