Language Search Complete
This commit is contained in:
parent
15e004dc7c
commit
4cad50e85b
3 changed files with 41 additions and 9 deletions
|
@ -85,7 +85,7 @@ struct csv* parse_line(char* line) {
|
||||||
void print_movies(struct node* head) {
|
void print_movies(struct node* head) {
|
||||||
|
|
||||||
if(!head) {
|
if(!head) {
|
||||||
printf("You F'd up mate (print_movies)");
|
printf("Yo F'd up mate (print_movies)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,14 @@ int integer_input(char* val) {
|
||||||
char *error = "";
|
char *error = "";
|
||||||
|
|
||||||
do {
|
do {
|
||||||
printf("\n%s\n%s",error, val);
|
printf("%s\n%s",error, val);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
read(STDIN_FILENO, buf, 127);
|
read(STDIN_FILENO, buf, 127);
|
||||||
num = atoi(buf);
|
num = atoi(buf);
|
||||||
|
|
||||||
error = "Input Error, try again.";
|
error = "\nInput Error, try again.";
|
||||||
|
|
||||||
} while(!num);
|
} while(!num);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "movies.h"
|
#include "movies.h"
|
||||||
|
|
||||||
|
int haschanged = 0;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
if(argc < 2) {
|
if(argc < 2) {
|
||||||
|
@ -42,7 +44,7 @@ int menu() {
|
||||||
printf("1. Show movies released in the specified year\n");
|
printf("1. Show movies released in the specified year\n");
|
||||||
printf("2. Show highest rated movie for each year\n");
|
printf("2. Show highest rated movie for each year\n");
|
||||||
printf("3. Show the title and year of release of all movies in a specific language\n");
|
printf("3. Show the title and year of release of all movies in a specific language\n");
|
||||||
printf("4. Exit from the program\n\n");
|
printf("4. Exit from the program\n");
|
||||||
|
|
||||||
int option;
|
int option;
|
||||||
do {
|
do {
|
||||||
|
@ -52,13 +54,13 @@ int menu() {
|
||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
int year_print(struct csv* data, void* val) {
|
void year_print(struct csv* data, void* val) {
|
||||||
|
|
||||||
if(data->year != *(int*)val)
|
if(data->year != *(int*)val)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
printf("%s\n", data->title);
|
printf("%s\n", data->title);
|
||||||
return 1;
|
haschanged = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void movie_year(struct node* head) {
|
void movie_year(struct node* head) {
|
||||||
|
@ -67,10 +69,14 @@ void movie_year(struct node* head) {
|
||||||
int* val = malloc(sizeof(int));
|
int* val = malloc(sizeof(int));
|
||||||
|
|
||||||
*val = integer_input("Enter year to search movies from: ");
|
*val = integer_input("Enter year to search movies from: ");
|
||||||
|
haschanged = 0;
|
||||||
|
|
||||||
iterate_nodes(head, f, val);
|
iterate_nodes(head, f, val);
|
||||||
|
|
||||||
|
if(!haschanged) {
|
||||||
|
printf("No data about movies released in the year %d", *val);
|
||||||
|
}
|
||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,8 +86,34 @@ void movie_rate(struct node* head) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lang_print(struct csv* data, void* val) {
|
||||||
|
|
||||||
|
for(int i = 0; i < data->numlang; i++) {
|
||||||
|
|
||||||
|
if(!strcmp(val, data->languages[i])) {
|
||||||
|
printf("%d %s\n", data->year, data->title);
|
||||||
|
haschanged = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void movie_lang(struct node* head) {
|
void movie_lang(struct node* head) {
|
||||||
|
|
||||||
printf("stub\n");
|
void* f = &lang_print;
|
||||||
|
char val[41];
|
||||||
|
|
||||||
|
printf("Enter Language to search for: ");
|
||||||
|
fflush(stdout);
|
||||||
|
fgets(val, 40, stdin);
|
||||||
|
|
||||||
|
// Replace newline character with the null terminator
|
||||||
|
val[strlen(val)-1] = '\0';
|
||||||
|
|
||||||
|
haschanged = 0;
|
||||||
|
iterate_nodes(head, f, &val);
|
||||||
|
|
||||||
|
if(!haschanged)
|
||||||
|
printf("No data about movies released in %s\n", val);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue