-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinalReview.c
More file actions
93 lines (77 loc) · 2.15 KB
/
finalReview.c
File metadata and controls
93 lines (77 loc) · 2.15 KB
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
/**
* Parker Zach
* Final Review
*/
#include "finalReview.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char * deepCopy(const char *s);
char ** split(const char *str, char delimiter, int *n);
void freeStringArray(char **stringArray, int n);
int cmpInt(const void *a, const void *b);
int * getUniqueIntegers(const int *arr, int n, )
void initFilm(Film *f,
char * title,
char * directorFirstName,
char * directorLastName,
int year,
double rating) {
if(f == NULL) {
return;
}
f->title = deepCopy(title);
f->directorFirstName = deepCopy(directorFirstName);
f->directorLastName = deepCopy(directorLastName);
f->year = year;
f->rating = rating;
return;
}
char * filmToString(Film * f) {
char buffer[1000];
sprintf(buffer, "%s directed by %s, %s, (%d) %5.2f\n", f->title,
f->directorFirstName,
f->directorFirstName,
f->year,
f->rating);
return deepCopy(buffer);
}
void printFilms(Film * f, int n) {
for(int i=0; i<n; i++) {
char *s = filmToString(&films[i]);
printf("%s\n", s);
free(s);
}
}
int cmpByTitle(const void * a, const void * b) {
const Film *x = (const Film *)a;
const Film *y = (const Film *)b;
return strcmp(x->title, y->title);
}
int cmpByDirectorYear(const void * a, const void * b) {
const Film *x = (const Film *)a;
const Film *y = (const Film *)b;
int result = strcmp(x->directorLastName, y->directorLastName);
if(strcmp(result == 0) {
result = strcmp(x->directorFirstName, y->directorFirstName);
if(result == 0) {
return cmpInt(&(x->year), &(y->year));
} else {
return result;
}
} else {
return result;
}
}
int cmpByRating(const void * a, const void * b) {
const Film *x = (const Film *)a;
const Film *y = (const Film *)b;
if(x->rating < y->rating) {
return -1;
} else if(x->rating > y->rating) {
return 1;
} else {
return 0;
}
}
//DAY 2 Review