-
Notifications
You must be signed in to change notification settings - Fork 1
/
MusicPlayer.c
155 lines (131 loc) · 3.48 KB
/
MusicPlayer.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc.h>
/* MUSIC PLAYER IN C with Doubly Linked List
*
* Look my Github Account for Projects about Machine Learning,Cyber Security,Python...
* Other Projects : https://github.com/aydinnyunus
*
*
*/
struct Player *head = NULL;
struct Player{
char *link;
struct Player *next;
struct Player *previous;
};
struct Player *createNewNode (char *link){
struct Player *newNode = NULL;
newNode = malloc(sizeof(struct Player));
if (newNode != NULL)
{
newNode->next = NULL;
newNode->previous = NULL;
newNode->link = malloc(strlen(link) + 20);
strcpy(newNode->link, link);
printf("Created New Person at %p\n", newNode);
} else{
printf("FAIL");
}
return newNode;
}
void printMusic(){
if (head==NULL)
printf("List is Empty\n");
else{
printf("Link : %s\n",head->link);
printf("----------------------\n");
}
}
void insertAtTail(struct Player *current,char *link) {
struct Player* temp = head;
struct Player* newNode = createNewNode(link);
if(head == NULL) {
head = newNode;
current = head;
return;
}
while(temp->next != NULL) temp = temp->next; // Go To last Node
temp->next = newNode;
newNode->previous = temp;
}
void cleanList(){
struct Player *next;
while(head)
{
next = head->next;
printf("Cleaning %s..",head->link);
free(head);
head = next;
}
}
void printList(){
printf("List :\n");
struct Player *temp;
temp = head;
if(temp == NULL)
printf("List is empty !");
else
while(temp){
printf("----------------------\n");
printMusic();
temp = temp->next;
}
}
int main() {
struct Player *current = head;
char nick[100];
char *link=malloc(2000 * sizeof(char)) ;
x:
while(1){
printf("Enter a command or value (Q For Quit)");
printf("\n----------------------\n");
fgets(nick,64,stdin);
if(strcmp("q\n",nick) == 0)
{
printf("Quitting..\n");
break;
}
else if(strcmp("next\n",nick) == 0)
{
current = head->next;
printf("Next Link..\n");
ShellExecute(NULL, "open",current->link, NULL, NULL, SW_SHOWNORMAL);
printf("\n----------------------\n");
}
else if(strcmp("curr\n",nick) == 0)
{
if(current->next == NULL){
printf("You are in last !");
goto x;
}
printf("Open Link..\n");
ShellExecute(NULL, "open",current->link, NULL, NULL, SW_SHOWNORMAL);
printf("\n----------------------\n");
}
else if(strcmp("prev\n",nick) == 0)
{
if(current->previous == NULL){
printf("You are in first !");
goto x;
}
current = current->previous;
printf("Previous Link..\n");
ShellExecute(NULL, "open",current->link, NULL, NULL, SW_SHOWNORMAL);
printf("\n----------------------\n");
}
else if(strcmp("print\n",nick) == 0)
{
printf("Printing..\n");
printList();
}
else if(sscanf(nick,"%999s", link) != 0)
{
printf("Adding %s..\n",link);
insertAtTail(current,link);
}
}
cleanList();
return 0;
}