用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;
}
相关推荐
哲Zheᗜe༘15 小时前
了解学习Python编程之python基础
开发语言·python·学习
落日漫游15 小时前
数据结构笔试核心考点
java·开发语言·算法
Doro再努力15 小时前
数据结构04:力扣顺序表3道例题解题思路与代码实现
c语言·数据结构
疯狂吧小飞牛16 小时前
Lua C API 中的注册表介绍
java·c语言·lua
寻找华年的锦瑟16 小时前
Qt-配置文件(INI/JSON/XML)
开发语言·qt
HY小海16 小时前
【C++】AVL树实现
开发语言·数据结构·c++
workflower16 小时前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程
Roc-xb16 小时前
ModuleNotFoundError: No module named ‘conda_token‘
开发语言·python·conda
人工干智能17 小时前
Python 开发中:`.ipynb`(Jupyter Notebook 文件)和 `.py`(Python 脚本文件)
开发语言·python·jupyter
Jay-juice17 小时前
QT信号与槽
开发语言·qt