Skip to content

Commit e88ce2e

Browse files
committed
feat: Add method to get song, aritist and length
1 parent 1dddecc commit e88ce2e

File tree

7 files changed

+166
-19
lines changed

7 files changed

+166
-19
lines changed

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"stdio.h": "c"
4+
}
5+
}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</h1>
88

99
<h2 align="center">
10-
BTS implemantation in C
10+
BST implemantation in C
1111
</h2>
1212

1313
<p align="center">
@@ -29,10 +29,10 @@ A binary search trees (BST) is a container that allows fast lookup, addition and
2929
</br></br>
3030

3131
<h2>About:</h2>
32-
Evaluation Project for the Data Structure course from Big Data at IESB.
32+
Assignment for the Data Structure course from Big Data at IESB.
3333
</br></br>
3434

35-
This project implements in a working and optimal way a BTS using C as a programming language.
35+
This project implements in a working and optimal way a BST using C as a programming language.
3636
</br></br>
3737

3838

code/main.c

+60-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
struct node {
55
int length; // node will store int length
6-
char artist; // node will store char artist name
7-
char songName; // node will store char song name
6+
char* artist; // node will store char artist name
7+
char* songName; // node will store char song name
88

99
struct node *right_child; // right child
1010
struct node *left_child; // left child
@@ -29,10 +29,12 @@ struct node* find_minimum(struct node *root) {
2929

3030
//function to create a node
3131

32-
struct node* new_node(int x) {
32+
struct node* new_node(int x, char* y, char* z) {
3333
struct node *p;
3434
p = malloc(sizeof(struct node));
3535
p->length = x;
36+
p->artist = y;
37+
p->songName = z;
3638
p->left_child = NULL;
3739
p->right_child = NULL;
3840

@@ -91,8 +93,62 @@ struct node* delete(struct node *root, int x) {
9193
}
9294

9395

96+
void result(struct node *root) {
97+
if(root!=NULL) {
98+
printf("%d", root->length);
99+
}
100+
}
101+
102+
void split_string( char lines[] ){
103+
lines;
104+
int i = 0;
105+
char *p = strtok (lines, "/");
106+
char *array[3];
107+
108+
while (p != NULL)
109+
{
110+
array[i++] = p;
111+
p = strtok (NULL, "/");
112+
}
113+
for (i = 0; i < 3; ++i)
114+
printf("%s\n", array[i]);
115+
}
94116

95117
int main() {
96118

97-
return 0;
119+
// struct node *root;
120+
// root = new_node(array[2])
121+
122+
// open song-list
123+
FILE * fpointer = fopen("song-list.txt", "r");
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+
fclose(fpointer);
153+
return 0;
98154
}
File renamed without changes.
File renamed without changes.

code/teste.c

+89-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,95 @@
11
#include <stdio.h>
2-
struct horario {
3-
int horas;
4-
int minutos;
5-
int segundos;
6-
};
7-
int main(void) {
2+
#include <stdlib.h>
3+
#include <string.h>
84

9-
struct horario agora;
105

11-
agora.horas = 15;
12-
agora.minutos = 17;
13-
agora.segundos = 30;
6+
typedef struct {
7+
char songName[50];
8+
char artist[50];
9+
int length;
10+
}Song;
1411

15-
printf("%i:%i:%i", agora.horas, agora.minutos, agora.segundos);
12+
typedef struct {
13+
Song song;
1614

17-
return 0;
15+
struct Node *right_child; // right child
16+
struct Node *left_child; // left child
17+
}Node;
18+
19+
20+
21+
int main ()
22+
{
23+
Song s;
24+
25+
26+
27+
28+
29+
30+
// open song-list
31+
FILE * fpointer = fopen("song-list.txt", "r");
32+
char song[50];
33+
char artist[50];
34+
char length_char[50];
35+
int length;
36+
char buf[] ="abc/qwe/ccd";
37+
int i = -1;
38+
int j = 0;
39+
40+
char line[255];
41+
42+
while(fgets(line, sizeof line, fpointer) != NULL) {
43+
// printf("%s\n", line);
44+
char c = line[0];
45+
46+
47+
i = -1;
48+
j = 0;
49+
50+
while (c != ',') {
51+
s.songName[i++] = c;
52+
c = line[j++];
53+
}
54+
s.songName[i++] = '\0';
55+
56+
printf("%s\n", s.songName);
57+
58+
59+
60+
61+
i = 0;
62+
c = line[j++];
63+
64+
while (c != ',') {
65+
s.artist[i++] = c;
66+
c = line[j++];
67+
}
68+
s.artist[i++] = '\0';
69+
70+
71+
printf("%s\n", s.artist);
72+
73+
74+
75+
76+
i = 0;
77+
c = line[j++];
78+
79+
while (c != '\n') {
80+
length_char[i++] = c;
81+
c = line[j++];
82+
}
83+
length_char[i++] = '\0';
84+
85+
86+
s.length = atoi(length_char);
87+
printf("%d\n", s.length);
88+
}
89+
90+
91+
92+
fclose(fpointer);
93+
94+
return 0;
1895
}

code/teste2.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
int main(void) {
4+
int a, *b;
5+
a = 15;
6+
*b = a;
7+
printf("Valor de p: %d. \n", *b);
8+
return 0;
9+
}

0 commit comments

Comments
 (0)