⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 使用与检验.cpp

📁 ns2的tcl脚本的解析器,能够解析简单的有限网络下的tcl脚本,并保存为.data文件
💻 CPP
字号:
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
#include "提取定义语句.h"
#include "搜索关键词.h"
#include "对于定义的操作.h"

extern int count;	
extern struct buffer *now; 
extern struct buffer *head;

//一些头结点的初始化函数
void inicial()
{
	strcpy(head->word,"\0"); 
	head->next=NULL;
	count=0;
	now=head;
}
struct topo *inicial_result(struct topo *result)
{
	
	result->linkhead=(LINK *)malloc(sizeof(LINK));
	result->nodehead=(NODE *)malloc(sizeof(NODE));
	result->linkhead->end=result->linkhead->from=0;
	result->linkhead->next=NULL;
	result->nodehead->seq=0;
	result->nodehead->next=NULL;
	return(result);
}
//输出部分
void nodecout(struct NODE *nodehead)
{	
	struct NODE *temp;
	temp=nodehead->next;
	while(temp!=NULL)
	{
		printf("%s\t%d\n",temp->name,temp->seq);
		temp=temp->next;
	}
}
void linkcout(struct LINK *linkhead)
{
	struct LINK *temp;
	temp=linkhead->next;
	while(temp!=NULL)
	{
		printf("from NO.%d to NO.%d\t%s\n",temp->from,temp->end,temp->capability);
		temp=temp->next;
	}
}
	
//主函数部分
void main()
{
	char *ch;
	int flag=0;
	FILE *fp;
	struct buffer *temp;
	struct topo *result;

	result=(topo *)malloc(sizeof(topo));
	result=inicial_result(result);

	head=(buffer *)malloc(sizeof(buffer));
	inicial();

	ch=(char *)malloc(sizeof(char));
	fp=fopen("E:\\毕业设计\\程序\\功能块\\搜索模块\\test.txt","r");
	
	if(fp==NULL)printf("the file can't be opened\n");

	*ch=fgetc(fp);
	while(*ch!=EOF)//文件结束为止
	{
		while(*ch!=EOF&&flag==0)//搜索到关键字为止
		{
			*ch=pre_getting(ch,fp);
			if(*ch!=EOF) flag=search(fp,ch,head);//search提供的就是一个flag,并有一个限长的缓冲区
		}
		if(flag!=0)
		{
			temp=gather(flag,fp);//gather提供的是一个定义语句的头指针
			result=operate(result,temp,flag);//operate提供的是分别挂在result上的结点,链路表
			inicial();//每次结束清空缓冲区
		}
		flag=0;
	}
	nodecout(result->nodehead);
	linkcout(result->linkhead); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -