#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();
}
poj_1028 Web Navigation
最新推荐文章于 2022-03-11 14:41:23 发布
这篇博客介绍了一个C语言实现的程序,用于模拟Web浏览器的导航操作,包括回退、前进、访问新网址和退出。程序使用链表结构存储URL历史,当输入特定命令时,根据命令更新当前访问的URL。通过示例代码,读者可以理解如何处理这些基本的Web导航功能。
摘要由CSDN通过智能技术生成