Functionally stubbed menu

This commit is contained in:
stitchy 2023-10-13 01:39:26 -07:00
parent 14a6bd5df5
commit 22d475db00
Signed by: stitchy
SSH key fingerprint: SHA256:yz2SoxdnY67tfY5Jzb0f2v8f5W3o/IF359kbcquWip8
7 changed files with 106 additions and 7 deletions

View file

@ -1,11 +1,15 @@
#include "csv_parser.h"
struct node* parse_csv() {
struct node* parse_csv(char* name) {
FILE * file;
file = fopen("movies_sample_1.csv", "r");
file = fopen(name, "r");
if(!file) {
printf("Your File was Stolen by the Gremlins\n");
exit(66);
// Buffer File For chars
}
// Buffer File For chars
char* buffer;
size_t buff_size = 1000;
size_t chars = -2;
@ -31,6 +35,8 @@ struct node* parse_csv() {
free(buffer);
fclose(file);
printf("Processed file %s and processed data for %d movies.\n\n", name, count_nodes(head));
return head;
}

View file

@ -17,7 +17,7 @@ struct csv {
struct node* node;
};
struct node* parse_csv();
struct node* parse_csv(char*);
struct csv* parse_line(char*);

View file

@ -10,5 +10,8 @@ csv_parser.o: csv_parser.c csv_parser.h
node.o: node.c node.h
$(CC) -c node.c -o node.o
run:
./movies movies_sample_1.csv
clean:
rm -f *.o vgcore.* $(output)

View file

@ -1,12 +1,71 @@
#include "movies.h"
int main() {
int main(int argc, char** argv) {
struct node* head = parse_csv();
if(argc < 2) {
printf("Please Specify Filename\n");
return 64;
}
printf("Test\n");
struct node* head = parse_csv(argv[1]);
enum OPTIONS menu_select = 0;
while(1) {
menu_select = menu();
switch(menu_select) {
case YEAR:
movie_year(head);
break;
case RATE:
movie_rate(head);
break;
case LANGUAGE:
movie_lang(head);
break;
case EXIT:
printf("Goodbye~\n");
return 0;
default:
printf("You naughty~ Pick a correct option next time.\n");
}
}
print_movies(head);
return 0;
}
int menu() {
int option = 0;
printf("1. Show movies released in the specified 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("4. Exit from the program\n\n");
while(option > 4 || option < 1) {
printf("Enter a choice from 1 to 4: ");
scanf("%i", &option);
}
return option;
}
void movie_year(struct node* head) {
printf("stub\n");
}
void movie_rate(struct node* head) {
printf("stub\n");
}
void movie_lang(struct node* head) {
printf("stub\n");
}

View file

@ -9,5 +9,18 @@
#include "csv_parser.h"
#include "node.h"
int menu();
void movie_year(struct node*);
void movie_rate(struct node*);
void movie_lang(struct node*);
enum OPTIONS {
YEAR = 1,
RATE = 2,
LANGUAGE = 3,
EXIT = 4,
};
#endif

View file

@ -28,3 +28,20 @@ struct node* appendv_node(struct node* head, void* data) {
return node;
}
int count_nodes(struct node* head) {
int num = 1;
if(!head)
return -1;
struct node* temp = head;
while(temp->node) {
temp = temp->node;
num++;
}
return num;
}

View file

@ -12,5 +12,6 @@ void append_node(struct node*, struct node*);
struct node* appendv_node(struct node*, void*);
int count_nodes(struct node*);
#endif