用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;
}
相关推荐
泓博21 分钟前
KMP(Kotlin Multiplatform)简单动画
android·开发语言·kotlin
芒果快进我嘴里1 小时前
C++打印乘法口诀表
开发语言·c++
1 小时前
Lua基础复习之Lua元表
开发语言·lua
可能是猫猫人1 小时前
【Python打卡Day39】图像数据与显存 @浙大疏锦行
开发语言·python
爬虫程序猿1 小时前
利用 Python 爬虫获取 Amazon 商品详情:实战指南
开发语言·爬虫·python
_w_z_j_1 小时前
C++----剖析stack、queue
开发语言·c++
电院工程师1 小时前
2.4 Python基础概念:通过一个文字冒险游戏学习编程
开发语言·python·学习·算法·游戏·游戏程序
设计师小聂!1 小时前
vue3 - 自定义hook
开发语言·javascript·ecmascript
风起云涌~1 小时前
【Java】BlockQueue
java·开发语言
猫头虎2 小时前
【Python系列PyCharm实战】ModuleNotFoundError: No module named ‘sklearn’ 系列Bug解决方案大全
android·开发语言·python·pycharm·bug·database·sklearn