From aa5045a797990fa93076bbf44c61ef9ef8989a7f Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Mon, 20 Nov 2023 10:24:31 +0100 Subject: [PATCH] commit --- conf.c | 34 +++++++++++++++++++++++++++++++--- conf.h | 2 ++ main.c | 8 ++++---- screenManager.c | 7 ++++--- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/conf.c b/conf.c index 38eb1e4..9f8f9f6 100644 --- a/conf.c +++ b/conf.c @@ -3,6 +3,19 @@ #include #include "conf.h" +int findConfId(ptConf confChain) { + ptConf px = confChain; + int max = 0; + + while (px -> next != NULL) { + if (px -> id > max) { + max = px -> id; + } + } + + return max + 1; +} + ptConf newConfChain() { ptConf confChain = (ptConf) malloc(sizeof(tConf)); @@ -11,13 +24,14 @@ ptConf newConfChain() { return confChain; } -void addConf(ptConf confChainStart, char title[], char speaker[], int day, int month, int year) { - ptConf px = confChainStart; +void addConf(ptConf confChain, char title[], char speaker[], int day, int month, int year) { + ptConf px = confChain; while (px -> next != NULL) { px = px -> next; } + px -> id = findConfId(confChain); px -> day = day; px -> month = month; px -> year = year; @@ -28,6 +42,19 @@ void addConf(ptConf confChainStart, char title[], char speaker[], int day, int m px -> next -> next = NULL; } +int findListenerId(ptListener listenerChain) { + ptListener px = listenerChain; + int max = 0; + + while (px -> next != NULL) { + if (px -> id > max) { + max = px -> id; + } + } + + return max + 1; +} + ptListener newListenerChain() { ptListener listenerChain = (ptListener) malloc(sizeof(tListener)); @@ -44,6 +71,7 @@ void addListener(ptListener listenerChain, char name[], int age, int level) { px = px -> next; } + px -> id = findListenerId(listenerChain); strcpy(px -> name, name); px -> age = age; px -> level = level; @@ -51,4 +79,4 @@ void addListener(ptListener listenerChain, char name[], int age, int level) { px -> next = (ptListener) malloc(sizeof(tListener)); px -> next -> next = NULL; px -> next -> prev = px; -} \ No newline at end of file +} diff --git a/conf.h b/conf.h index c33ec37..d48ade3 100644 --- a/conf.h +++ b/conf.h @@ -4,6 +4,7 @@ struct listenerList; typedef struct conf { + int id; char title[30]; char speaker[20]; int day; @@ -19,6 +20,7 @@ typedef struct confList { } tConfList; typedef struct listener { + int id; char name[20]; int age; int level; diff --git a/main.c b/main.c index cc9faff..cc8df3e 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,7 @@ int main() { - /*ptConf confChain = newConfChain(); + ptConf confChain = newConfChain(); ptListener listenerChain = newListenerChain(); addConf(confChain, "test", "tesst", 21, 120, 2023); @@ -26,9 +26,9 @@ int main() while (py -> next != NULL) { printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level); py = py -> next; - }*/ + } - menu(); + //menu(); return 0; -} \ No newline at end of file +} diff --git a/screenManager.c b/screenManager.c index 80fb1bd..200aab0 100644 --- a/screenManager.c +++ b/screenManager.c @@ -58,8 +58,9 @@ void drawRectangle(int x, int y, int lenght, int height) void drawMenu(char *options[], int lenght) { int max = strlen(options[0]); + int i; - for (int i = 0; i < lenght; i++) { + for (i = 0; i < lenght; i++) { if (strlen(options[i]) > max) { max = strlen(options[i]); } @@ -72,7 +73,7 @@ void drawMenu(char *options[], int lenght) { drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4); - for (int i = 0; i < lenght; i++) { + for (i = 0; i < lenght; i++) { goToCoords((columns - max - 4) / 2 + 2, 4 + i); printf("%s", options[i]); } @@ -174,4 +175,4 @@ void menu() default: break; } -} \ No newline at end of file +}