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
|
#include "../include/video.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Video
createVideo (char *title, char *author, char *id, char *duration)
{
Video video;
if (title != NULL && strlen (title) > 0)
{
video.title = (char *)calloc (strlen (title) + 1, sizeof (char));
strcpy (video.title, title);
}
if (author != NULL && strlen (author) > 0)
{
video.author = (char *)calloc (strlen (author) + 1, sizeof (char));
strcpy (video.author, author);
}
if (id != NULL && strlen (id) > 0)
{
video.id = (char *)calloc (strlen (id) + 1, sizeof (char));
strcpy (video.id, id);
}
if (duration != NULL && strlen (duration) > 0)
{
video.duration = (char *)calloc (strlen (duration) + 1, sizeof (char));
strcpy (video.duration, duration);
}
return video;
}
void
printVideo (char *format, Video *videos, int numberOfVideos)
{
if (format != NULL && strlen (format) > 0)
{
for (int i = 0; i < numberOfVideos; i++)
{
for (int j = 0; j < strlen (format); j++)
{
switch (format[j])
{
case 'a':
printf ("%s", videos[i].author);
break;
case 'd':
printf ("%s", videos[i].duration);
break;
case 'i':
printf ("%s", videos[i].id);
break;
case 't':
printf ("%s", videos[i].title);
break;
case 'R':
printf ("\n");
break;
case 'T':
printf ("\t");
break;
default:
if (!isalpha (format[j]))
{
printf ("%c", format[j]);
}
}
}
printf ("\n");
}
}
else
{
for (int i = 0; i < numberOfVideos; i++)
{
printf ("%s\t%s\n", videos[i].id, videos[i].title);
}
}
}
void
freeVideo (Video *v)
{
free (v->title);
free (v->author);
free (v->id);
free (v->duration);
}
|