-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-history-management.c
99 lines (98 loc) · 2.73 KB
/
browser-history-management.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_HISTORY_SIZE 10
struct Webpage {
char url[100];
time_t timestamp;
struct Webpage *prev;
struct Webpage *next;
};
struct Webpage *history = NULL;
void addWebpage(char url[]) {
struct Webpage *newPage = (struct Webpage *)malloc(sizeof(struct Webpage));
strcpy(newPage->url, url);
newPage->timestamp = time(NULL);
newPage->prev = NULL;
newPage->next = history;
if (history != NULL) {
history->prev = newPage;
}
history = newPage;
}
void displayHistory() {
struct Webpage *current = history;
while (current != NULL) {
printf("URL: %s, Timestamp: %s", current->url, asctime(localtime(&(current->timestamp))));
current = current->next;
}
}
void clearHistory() {
struct Webpage *current = history;
while (current != NULL) {
struct Webpage *temp = current;
current = current->next;
free(temp);
}
history = NULL;
}
void deleteWebpage(char url[]) {
struct Webpage *current = history;
while (current != NULL) {
if (strcmp(current->url, url) == 0) {
if (current->prev != NULL) {
current->prev->next = current->next;
} else {
history = current->next;
}
if (current->next != NULL) {
current->next->prev = current->prev;
}
free(current);
return;
}
current = current->next;
}
printf("URL not found in history.\n");
}
int main() {
char input[100];
char deleteInput[100];
int choice;
while (1) {
printf("\n1. Enter URL to add to history.\n");
printf("2. Display browsing history.\n");
printf("3. Enter URL to delete history.\n");
printf("4. Clear history.\n");
printf("5. Exit.\n");
printf("Enter your choice: ");
scanf("%d", &choice);
printf("\n");
switch(choice){
case 1:
printf("Enter URL to add to browser history: ");
scanf("%s", input);
addWebpage(input);
break;
case 2:
printf("Browsing History:\n");
displayHistory();
break;
case 3:
printf("Enter a URL to delete from history: ");
scanf("%s", deleteInput);
deleteWebpage(deleteInput);
break;
case 4:
clearHistory();
printf("History cleared.\n");
break;
case 5:
exit(0);
default:
printf("Invalid choice. Please try again\n");
}
}
return 0;
}