From c7631b1a1485855e7c29863de463909e8daf236f Mon Sep 17 00:00:00 2001 From: paulusja Date: Thu, 9 Oct 2025 13:43:59 +0200 Subject: [PATCH] Add current status of second lecture. --- 01_modultechnik/main.c | 4 ++-- 01_modultechnik/namesarchive.c | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/01_modultechnik/main.c b/01_modultechnik/main.c index eaf8b70..d172398 100644 --- a/01_modultechnik/main.c +++ b/01_modultechnik/main.c @@ -30,7 +30,7 @@ int main() printf("\nNach Eingabe:\n"); printNames(); - printf("\nNach Sortierung:\n"); + /*printf("\nNach Sortierung:\n"); sortNames(); printNames(); printf("\n"); @@ -56,7 +56,7 @@ int main() } printf("\nNach Entfernen:\n"); - printNames(); + printNames();*/ return EXIT_SUCCESS; } diff --git a/01_modultechnik/namesarchive.c b/01_modultechnik/namesarchive.c index 7eaabac..a0a071d 100644 --- a/01_modultechnik/namesarchive.c +++ b/01_modultechnik/namesarchive.c @@ -2,3 +2,41 @@ #include #include #include + +static char names[MAX_NAMES][MAX_NAME_LEN+1]; +static unsigned int numberOfEntries = 0; + +/* +static void cpy(char *dst, const char *src, unsigned int max) +{ + int i; + for(i = 0; i < max && *src != '\0'; i++) + { + *dst = *src; + dst++; + src++; + } + if(i < max) + *dst = '\0'; +}*/ + +int addName(const char *name) +{ + if(numberOfEntries < MAX_NAMES) + { + strncpy(names[numberOfEntries], name, MAX_NAME_LEN+1); + names[numberOfEntries][MAX_NAME_LEN] = '\0'; + numberOfEntries++; + return 1; + } + + return 0; +} + +void printNames() +{ + for(int i = 0; i < numberOfEntries; i++) + { + printf("%s\n", names[i]); + } +} \ No newline at end of file