poj_1028 Web Navigation

这篇博客介绍了一个C语言实现的程序,用于模拟Web浏览器的导航操作,包括回退、前进、访问新网址和退出。程序使用链表结构存储URL历史,当输入特定命令时,根据命令更新当前访问的URL。通过示例代码,读者可以理解如何处理这些基本的Web导航功能。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define C_MAX 70
struct weburl
{
	char url[C_MAX];
	struct weburl *next;
	struct weburl *prev;	
};

void  web_navigation()
{
	char temp[70];
	struct weburl *head = (struct weburl *)malloc(sizeof(struct weburl));
	struct weburl *p2 = head;
	struct weburl *p1 =NULL;
        struct weburl *tp =NULL;
	struct weburl *newurl =NULL;
	strcpy(head->url,"http://www.acm.org/");
	head->next = NULL;
	head->prev = NULL;
	
	while(scanf("%s",temp)!=EOF)
	{
		if(strcmp(temp,"BACK") == 0)
		{
			if(p2->prev != NULL)
			 {
				p2 = p2->prev;
				printf("%s\n",p2->url);
			 }
			else
			{
				printf("Ignored\n");
			}
	        }
		 else if(strcmp(temp,"FORWARD") == 0)
		{
			if(p2->next != NULL)
			 {
				p2 = p2->next;
				printf("%s\n",p2->url);
			 }
			else
			{
				printf("Ignored\n");
			}
	        }
		else if(strcmp(temp,"VISIT") == 0)
		{
			newurl = (struct weburl*)malloc(sizeof(struct weburl));
			scanf("%s",newurl->url);
			newurl->next = NULL;
			newurl->prev = p2;
			p1 = p2->next;
			p2->next = newurl;
			p2 = newurl;
                        tp =p1;
   			while(tp != NULL)
  			 {
			    p1 = p1->next;
  			    free(tp);
			    tp=p1;
			 }
			 p1 =NULL;
			printf("%s\n",newurl->url);
		}
		else if(strcmp(temp,"QUIT") == 0)
		{
		  goto exit;
		}
		memset(temp,0,sizeof(temp)/sizeof(temp[0]));
	}
exit:
   tp = head;
   while(tp != NULL)
   {
      head = head->next;
      free(tp);
      tp = head;
   }
   tp =NULL;
    p2 =NULL;
    newurl =NULL;
    head = NULL;
}


int main(void)
{
  web_navigation();
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值