120 lines
2.7 KiB
C
120 lines
2.7 KiB
C
|
/* ----------------------------------------------------------------------------
|
||
|
* -- _____ ______ _____ -
|
||
|
* -- |_ _| | ____|/ ____| -
|
||
|
* -- | | _ __ | |__ | (___ Institute of Embedded Systems -
|
||
|
* -- | | | '_ \| __| \___ \ Zuercher Hochschule Winterthur -
|
||
|
* -- _| |_| | | | |____ ____) | (University of Applied Sciences) -
|
||
|
* -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
|
||
|
* ----------------------------------------------------------------------------
|
||
|
*/
|
||
|
/**
|
||
|
* @file
|
||
|
* @brief Lab implementation
|
||
|
*/
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include "person.h"
|
||
|
#include "list.h"
|
||
|
#include <string.h>
|
||
|
#define MAX_AGE 200
|
||
|
#define MIN_AGE 0
|
||
|
|
||
|
void getPerson(person_t *neu) {
|
||
|
|
||
|
int run = 1;
|
||
|
|
||
|
while(run == 1) {
|
||
|
printf("Enter Name: ");
|
||
|
char input[100];
|
||
|
scanf("%s",input); // evt limite
|
||
|
|
||
|
if(strlen(input) <= NAME_LEN) {
|
||
|
strcpy(neu->name,input);
|
||
|
run = 0;
|
||
|
} else {
|
||
|
printf("Falsche Eingabe!!\n");
|
||
|
}
|
||
|
while(getchar() != '\n') {}
|
||
|
}
|
||
|
|
||
|
run = 1;
|
||
|
|
||
|
while(run == 1) {
|
||
|
printf("Enter First Name: ");
|
||
|
char input[100];
|
||
|
scanf("%s",input);
|
||
|
|
||
|
if(strlen(input) <= NAME_LEN) {
|
||
|
strcpy(neu->first_name,input);
|
||
|
run = 0;
|
||
|
} else {
|
||
|
printf("Falsche Eingabe!!\n");
|
||
|
}
|
||
|
while(getchar() != '\n') {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
run = 1;
|
||
|
|
||
|
while(run == 1) {
|
||
|
int age = -1;
|
||
|
printf("Age: ");
|
||
|
if(scanf("%d",&age) != 0) {
|
||
|
neu->age = age;
|
||
|
run = 0;
|
||
|
} else {
|
||
|
printf("Falsche Eingabe!!\n");
|
||
|
}
|
||
|
while(getchar() != '\n') {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void insert(node_t *liste) {
|
||
|
person_t neu;
|
||
|
getPerson(&neu);
|
||
|
insert_list(liste,&neu);
|
||
|
}
|
||
|
|
||
|
void removeIt(node_t *liste) {
|
||
|
person_t del;
|
||
|
getPerson(&del);
|
||
|
remove_list(liste,&del);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @brief Main entry point.
|
||
|
* @param[in] argc The size of the argv array.
|
||
|
* @param[in] argv The command line arguments...
|
||
|
* @returns Returns EXIT_SUCCESS (=0) on success, EXIT_FAILURE (=1) there is an expression syntax error.
|
||
|
*/
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
// BEGIN-STUDENTS-TO-ADD-CODE
|
||
|
node_t personen_liste;
|
||
|
personen_liste.next = &personen_liste;
|
||
|
int run = 1;
|
||
|
|
||
|
while(run == 1) {
|
||
|
char cmd[100];
|
||
|
printf("I to Insert new Person\nR to Remove Person\nS to Show List\nC to Clear all\nE to End\n-> ");
|
||
|
scanf("%s",cmd);
|
||
|
if(cmd[0] == 'I') {
|
||
|
insert(&personen_liste);
|
||
|
}else if(cmd[0] == 'E') {
|
||
|
run = 0;
|
||
|
}else if(cmd[0] == 'R') {
|
||
|
removeIt(&personen_liste);
|
||
|
}else if(cmd[0] == 'S') {
|
||
|
show_list(&personen_liste);
|
||
|
}else if(cmd[0] == 'C') {
|
||
|
clear_list(&personen_liste);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// END-STUDENTS-TO-ADD-CODE
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|