This commit is contained in:
Lukian LEIZOUR 2023-11-20 10:24:31 +01:00
parent 50ea8f2735
commit aa5045a797
4 changed files with 41 additions and 10 deletions

32
conf.c
View file

@ -3,6 +3,19 @@
#include <string.h>
#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;

2
conf.h
View file

@ -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;

6
main.c
View file

@ -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;
}

View file

@ -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]);
}