用c 编写的笔记搜索程序

@{@XXX文本记录@}@ 文本记录格式 xxx 搜索词条

复制代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	FILE *f=fopen("help.txt","r");
	if(f==NULL){
		perror("file");
		return -1;
	}
	char nr[2000];
        
	fseek(f,0,SEEK_END);
	long len=ftell(f);


	rewind(f);
   
        char txt2[len];
	for(int t=0;t<len;t++){
		txt2[t]=fgetc(f);
	}
//	fclose(f);

  	int d=0;
	int  wz=0;
	char txt1[10];

       char bz1[10]; 
       int t=0;
       int k=0;
       char txt[len];
       char bz[14];

a:       scanf("%s",bz1);
	 strcpy(bz,"@{@");
 	memcpy(txt,txt2,len);	 
	 strcat(bz,bz1);
         
	 printf("%s\n",bz);
	 d=0;
	 wz=0;
	 memset(nr,0,2000);

	for(int t=0;t<(len-4);t++){
		if(t==(len-3))  break;
		if(((txt[t]=='@')&&(txt[t+1]=='{')&&(txt[t+2]=='@'))||(wz==1)){
			wz=1;
			nr[d]=txt[t];
	 		d++;
		
						
		}

		if((txt[t]='@')&&(txt[t+1]=='}')&&(txt[t+2]=='@')) {
			d=0; 	   
		       wz=0;

	       		memset(txt1,0,10);	       
       		       memcpy(txt1,nr,strlen(bz));

		       if(memcmp(bz,txt1,strlen(bz))==0){

		       		system("clear");
	              		printf("%s\n",nr);
		      		memset(nr,0,2000);
				memset(bz,0,10);
			    
       				goto a;
		       }
			memset(nr,0,2000);
			
		}
		
	}

      
	puts("没有匹配函数");
       goto a;
	return 0;
}
相关推荐
炸膛坦客6 小时前
单片机/C/C++八股:(二十六)IIC 专题(I²C)---- 上集
c语言·c++·单片机
灯澜忆梦6 小时前
GO_并发编程---定时器
开发语言·后端·golang
-银雾鸢尾-6 小时前
C#中的StringBuilder相关方法
开发语言·c#
-银雾鸢尾-6 小时前
C#中结构体与类的区别;抽象类与接口的区别
开发语言·c#
大模型码小白7 小时前
【Python零基础教程】继承、多态与魔法函数:面向对象编程三大核心特性详解
java·大数据·开发语言·人工智能·python·ai编程
段一凡-华北理工大学9 小时前
向量数据库实战:选型、调优与落地~系列文章12:文本分块策略实战:chunk_size 怎么选?重叠多少?
开发语言·数据库·后端·oracle·rust·工业智能体·高炉智能化
Ljwuhe10 小时前
C++——多态
开发语言·c++
遇乐的果园10 小时前
前端学习笔记-vue加载渲染优化
前端·笔记·学习
心平气和量大福大10 小时前
C#-WPF-Window主窗体
开发语言·c#·wpf
遇乐的果园11 小时前
前端学习笔记-vue状态管理优化
前端·笔记·学习