-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathartista.c
81 lines (62 loc) · 1.72 KB
/
artista.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
#include "artista.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct artista
{
char id[TAM_ID];
char n_seguidores[TAM_N_SEGUIDORES];
char *generos;
char *nome;
int popularidade;
int qtd_add_playlist;
};
// ============ ESTRUTURA ============
Artista Artista_cria()
{
Artista a = (Artista)calloc(1, sizeof(struct artista));
a->generos = (char *)malloc(TAM_GENEROS * sizeof(char));
a->nome = (char *)malloc(TAM_NOME_ARTISTA * sizeof(char));
a->qtd_add_playlist = 0;
return a;
}
Artista *Artistas_vetor_constroi()
{
Artista *a = (Artista *)calloc(QTD_INICIAL, sizeof(Artista));
return a;
}
void Artistas_destroi(Artista *a, int qtd_alocada)
{
for (int i = 0; i < qtd_alocada; i++)
{
free(a[i]->nome);
free(a[i]->generos);
free(a[i]);
}
free(a);
}
// ============ LEITURA ============
Artista Artista_le(Artista a, FILE *f)
{
fscanf(f, "%[^;];", a->id);
fscanf(f, "%[^;];", a->n_seguidores);
fscanf(f, "%[^;];", a->generos);
fscanf(f, "%[^;];", a->nome);
fscanf(f, "%d\n", &a->popularidade);
return a;
}
// ============ FUNCIONALIDADE ============
void Lista_artistas(char *artista, Artista *a, int artistas_usado)
{
for (int i = 0; i < artistas_usado; i++)
{
if (strcmp(artista, a[i]->nome) == 0)
{
printf(" -nome: \033[90m%s\033[0m;\n", a[i]->nome);
printf(" -id: \033[90m%s\033[0m;\n", a[i]->id);
printf(" -seguidores: \033[90m%s\033[0m;\n", a[i]->n_seguidores);
printf(" -generos: \033[90m%s\033[0m;\n", a[i]->generos);
printf(" -popularidade: \033[90m%d\033[0m;\n\n", a[i]->popularidade);
}
}
}