/*
 * interface.h
 *
 *  Created on: 24/02/2009
 *      Author: mateu hunter
 */

#ifndef INTERFACE_H_
#define INTERFACE_H_

#include "model.h"
#define MAX_NAME_LENGTH 64

struct node* create_initial_person(void);
struct node* add_person(struct node *head);
struct node* delete_person(struct node *head);
struct node* get_person(struct node *head);

void search_by_first_name(struct node *head);
void search_by_first_name(struct node *head);
void print_menu(void);

struct node* create_initial_person(void) {
    struct node *head = NULL;
    char *first_name = (char *) malloc(MAX_NAME_LENGTH);
    char *last_name = (char *) malloc(MAX_NAME_LENGTH);
    /*    first_name = "michael";
     last_name = "franti"; */

    printf("Enter the first name:\n");
    scanf("%s", first_name);
    printf("Enter the last name:\n");
    scanf("%s", last_name);
    printf("Created initial node for: %s %s.\n", first_name, last_name);
    head = create_initial_node(first_name, last_name);
    return head;
}

struct node* add_person(struct node *head) {
    char *first_name = (char *) malloc(MAX_NAME_LENGTH);
    char *last_name = (char *) malloc(MAX_NAME_LENGTH);
    int position;
    /*    first_name = "michael";
     last_name = "franti"; */

    printf("Enter the first name:\n");
    scanf("%s", first_name);
    printf("Enter the last name:\n");
    scanf("%s", last_name);
    printf("Enter the position number, in the zero-based list, for this person:\n");
    scanf("%d", &position);
    head = add_node(head, first_name, last_name, position);
    return head;
}

struct node* get_person(struct node *head) {
    int position;
    /*    first_name = "michael";
     last_name = "franti"; */

    printf("Enter the position in the (zero-based) list for this person:\n");
    scanf("%d", &position);
    printf("Got node for position %d.\n", position);
    return get_node(head, position);
}

struct node* delete_person(struct node *head) {
    int position;
    /*    first_name = "michael";
     last_name = "franti"; */

    printf("Enter the position in the (zero-based) list to delete:\n");
    scanf("%d", &position);
    printf("Deleting node for position %d.\n", position);
    return delete_node(head, position);
}

void search_by_first_name(struct node *head) {
    char *first_name = (char *) malloc(MAX_NAME_LENGTH);
    printf("Enter first name to search on:\n");
    scanf("%s", first_name);
    printf("Searching for people with first name %s...\n", first_name);
    search_nodes(head, 'f', first_name);
    free(first_name);
}

void search_by_last_name(struct node *head) {
    char *last_name = (char *) malloc(MAX_NAME_LENGTH);
    printf("Enter last name to search on:\n");
    scanf("%s", last_name);
    printf("Searching for people with first name %s...\n", last_name);
    search_nodes(head, 'l', last_name);
    free(last_name);
}

void print_menu(void) {
    printf("\nMENU: Pick option number below:\n\n");
    printf("0 create the first person to the list.\n");
    printf("a add a person to the list.\n");
    printf("g get the person in the nth position of the (zero-based) list.\n");
    printf("f first person.\n");
    printf("l last person.\n");
    printf("d delete person in nth position.\n");
    printf("1 1st name search.\n");
    printf("z last name search.\n");
    printf("r reverse the list.\n");
    printf("o order list by first or last name in either ascending or descending order.\n");
    printf("p Print all people.\n");
    printf("n Return the length of the list.\n");
    printf("m Print the menu.\n");
    printf("q Quit.\n\n");
}

#endif /* INTERFACE_H_ */
My tags:
 
Popular tags:
 
Powered by MojoMojo