/* * driver.c * * Created on: 22/02/2009 * Author: mateu hunter */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include "interface.h" #define VERBOSE 0 int main(int argc, char *argv[]) { char *input = (char *)malloc(sizeof(char *)); char selection; struct node *head = NULL; struct node *tail = NULL; struct node *cursor = NULL; print_menu(); printf("? "); scanf("%s", input); selection = *input; if (VERBOSE) { printf("Input %c\n", selection); } while (selection != 'q' && selection != '\0') { if (selection == '0') { /* Just in case someone is re-initializing. i.e head is not NULL * Keep those mallocs and frees equal. */ free_all_nodes(head); head = create_initial_person(); printf("? "); scanf("%s", input); selection = *input; continue; } else { if (head != NULL) { switch (selection) { case 'a': head = add_person(head); break; case 'g': cursor = get_person(head); printf("Got person: %s %s.\n", cursor->first_name, cursor->last_name); case 'f': printf("First person: %s %s.\n", head->first_name, head->last_name); break; case 'l': tail = get_tail_node(head); printf("Last person: %s %s.\n", tail->first_name, tail->last_name); break; case 'd': head = delete_person(head); break; case '1': search_by_first_name(head); break; case 'z': search_by_last_name(head); break; case 'r': head = reverse_nodes(head); break; case 'o': /* printf("Ordering exercise left for the reader, hahaha ;)\n"); */ head = sort_nodes(head, 1); break; case 'p': printf("\nTHE LIST:\n"); print_all_nodes(head); break; case '\0': printf("Input something doosh-bag.\n"); break; case '\n': printf("Input something other than \\n doosh-bag.\n"); break; case 'm': print_menu(); break; case 'n': printf("Number of nodes is: %d.\n", number_of_nodes(head)); break; default: printf("Invalid choice.\n"); print_menu(); break; } } else { printf( "\nHEY Holmes, you have to create the initial node before all else, select 0 (zero).\n"); } } printf("? "); scanf("%s", input); selection = *input; } printf("End of run.\n"); free_all_nodes(head); free(input); return EXIT_SUCCESS; } /* Quirks: * * Yes I should consider using strcpy when creating nodes. * * Only the first character in the input string is used for menu choices. * For example, if one input 'queue' the input select will be 'q' which * corresponds to an actual menu action 'quit'. * * The name lengths are limited to 64 characters. If you input something * larger than that, then results are unknown. You've been warned. * * First name or last name can not contain a space. Yeah, that's shitty, * but that's the way it is for now. * * Ordering is broken. It may chop off the last element and it may piss * valgrind off. I'd love to nail the ordering down, but the clock has struck * and it's time to move on. */
Showing changes from previous revision. Removed | Added
