大数据查找c

本文范例文本模拟开房数据文本,写到文件中,初级版本:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

char strpath[256] = "开房路径";
char savepath[256] = { 0 };

void  showlist(char str[256]) {

	sprintf(savepath, "C:\\%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, 2014, 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(savepath);
	system("pause");

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值