-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03_musicalbum_v0.c
165 lines (110 loc) · 4.06 KB
/
03_musicalbum_v0.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
156
157
158
159
160
161
162
163
164
/* Project 03 -- DOUBLY LINKED LIST
03_MUSICALBUM_V0.C
---------------
This is a college work using DOUBLY LINKED LIST.
It is the first try to get the solution.
I decided to abort because it give me no flexibility.
The project 10 is the continuation of this effort :)
Check it out o/
************************************************************
Output:
_____________________!!!!!WELCOME TO JR'PLAYLIST!!!!'_______________________
Do you What to enter a Track now (Y or N)?y
Please enter the Track Number: 1
Please enter the Artist Name: Pink Floyd
Please enter the Music Name: Stairway To Haven
Please enter the Track Duration (sec): 457
Do you What to enter a Track now (Y or N)?n
You added this(these) Music(s) in your album:
________________Tracks______List__________________
| Track | Artist Name |Music Title | Time(sec) |
--------------------------------------------------
| 1 | Pink Floyd | Stairway To Haven | 457 |
__________________________________________________
************************************************************
DOUBLY LINKED LIST:
Based on: book - Beginning C From Novice to Professional
4th Edition Pg 426 Author Ivor Horton
Chap 11 - Doubly Linked Lists
References:
https://en.wikipedia.org/wiki/Frank_Sinatra
https://en.wikipedia.org/wiki/The_Wall
http://www.caetanoveloso.com.br/
https://en.cppreference.com/w/c/io/fopen
UNINTER - Curso: Engenharia da Computacao
Escola Superior Politecnica
Author: Gilberto Jr RU 3326662
Edited: J3
Date: Dez, 2021
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char *argv[]) {
char filename[] = "music_album_data.csv";
char txt[150];
typedef struct Track {
int track;
char artist[50];
char music[50];
int duration;
struct Track *next;
struct Track *previous;
}Track_t;
Track_t *first = NULL;
Track_t *current = NULL;
Track_t *last = NULL;
char test = '\0';
int c;
printf("\n\n_____________________!!!!!WELCOME TO JR'PLAYLIST!!!!'_______________________\n\n");
for( ; ; )
{
printf("\nDo you What to enter a Track now (Y or N)?");
scanf(" %c", &test);
while ((c = getchar()) != '\n' && c != EOF) { }
if(tolower(test) == 'n') break;
current = (Track_t*) malloc(sizeof(Track_t));
if(first == NULL)
{
first = current;
current->previous = NULL;
}
else
{
last->next = current;
current->previous = last;
}
printf("\nPlease enter the Track Number: ");
scanf("%i", ¤t->track);
while ((c = getchar()) != '\n' && c != EOF) { }
printf("\nPlease enter the Artist Name: ");
gets(current->artist);
printf("\nPlease enter the Music Name: ");
gets(current->music);
printf("\nPlease enter the Track Duration (sec): ");
scanf("%i", ¤t->duration);
while ((c = getchar()) != '\n' && c != EOF) { }
current->next = NULL;
last = current;
}
FILE *fpt;
fpt = fopen(filename, "a+");
//fprintf(fpt,"Track,Artist_name,Music_title,Time(sec)\n");
printf ("\n You added this(these) Music(s) in your album:\n\n");
printf("________________Tracks______List__________________\n");
printf("| Track | Artist Name |Music Title | Time(sec) |\n") ;
printf("--------------------------------------------------\n");
while(current != NULL)
{
fprintf(fpt,"%i,%s,%s,%i\n", current->track, current->artist, current->music, current->duration);
printf("| %i | %s | %s | %i |\n", current->track, current->artist, current->music, current->duration);
last = current;
current = current->previous;
free(last);
}
printf("\n__________________________________________________\n");
printf("\n__________________________________________________\n");
fclose(fpt);
printf("\n %s file created sucessfully!\n\n",filename);
return 0;
}