commit
This commit is contained in:
parent
50ea8f2735
commit
aa5045a797
4 changed files with 41 additions and 10 deletions
34
conf.c
34
conf.c
|
@ -3,6 +3,19 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "conf.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 newConfChain() {
|
||||||
ptConf confChain = (ptConf) malloc(sizeof(tConf));
|
ptConf confChain = (ptConf) malloc(sizeof(tConf));
|
||||||
|
|
||||||
|
@ -11,13 +24,14 @@ ptConf newConfChain() {
|
||||||
return confChain;
|
return confChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addConf(ptConf confChainStart, char title[], char speaker[], int day, int month, int year) {
|
void addConf(ptConf confChain, char title[], char speaker[], int day, int month, int year) {
|
||||||
ptConf px = confChainStart;
|
ptConf px = confChain;
|
||||||
|
|
||||||
while (px -> next != NULL) {
|
while (px -> next != NULL) {
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
px -> id = findConfId(confChain);
|
||||||
px -> day = day;
|
px -> day = day;
|
||||||
px -> month = month;
|
px -> month = month;
|
||||||
px -> year = year;
|
px -> year = year;
|
||||||
|
@ -28,6 +42,19 @@ void addConf(ptConf confChainStart, char title[], char speaker[], int day, int m
|
||||||
px -> next -> next = NULL;
|
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 newListenerChain() {
|
||||||
ptListener listenerChain = (ptListener) malloc(sizeof(tListener));
|
ptListener listenerChain = (ptListener) malloc(sizeof(tListener));
|
||||||
|
|
||||||
|
@ -44,6 +71,7 @@ void addListener(ptListener listenerChain, char name[], int age, int level) {
|
||||||
px = px -> next;
|
px = px -> next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
px -> id = findListenerId(listenerChain);
|
||||||
strcpy(px -> name, name);
|
strcpy(px -> name, name);
|
||||||
px -> age = age;
|
px -> age = age;
|
||||||
px -> level = level;
|
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 = (ptListener) malloc(sizeof(tListener));
|
||||||
px -> next -> next = NULL;
|
px -> next -> next = NULL;
|
||||||
px -> next -> prev = px;
|
px -> next -> prev = px;
|
||||||
}
|
}
|
||||||
|
|
2
conf.h
2
conf.h
|
@ -4,6 +4,7 @@
|
||||||
struct listenerList;
|
struct listenerList;
|
||||||
|
|
||||||
typedef struct conf {
|
typedef struct conf {
|
||||||
|
int id;
|
||||||
char title[30];
|
char title[30];
|
||||||
char speaker[20];
|
char speaker[20];
|
||||||
int day;
|
int day;
|
||||||
|
@ -19,6 +20,7 @@ typedef struct confList {
|
||||||
} tConfList;
|
} tConfList;
|
||||||
|
|
||||||
typedef struct listener {
|
typedef struct listener {
|
||||||
|
int id;
|
||||||
char name[20];
|
char name[20];
|
||||||
int age;
|
int age;
|
||||||
int level;
|
int level;
|
||||||
|
|
8
main.c
8
main.c
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
/*ptConf confChain = newConfChain();
|
ptConf confChain = newConfChain();
|
||||||
ptListener listenerChain = newListenerChain();
|
ptListener listenerChain = newListenerChain();
|
||||||
|
|
||||||
addConf(confChain, "test", "tesst", 21, 120, 2023);
|
addConf(confChain, "test", "tesst", 21, 120, 2023);
|
||||||
|
@ -26,9 +26,9 @@ int main()
|
||||||
while (py -> next != NULL) {
|
while (py -> next != NULL) {
|
||||||
printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level);
|
printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level);
|
||||||
py = py -> next;
|
py = py -> next;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
menu();
|
//menu();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,9 @@ void drawRectangle(int x, int y, int lenght, int height)
|
||||||
|
|
||||||
void drawMenu(char *options[], int lenght) {
|
void drawMenu(char *options[], int lenght) {
|
||||||
int max = strlen(options[0]);
|
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) {
|
if (strlen(options[i]) > max) {
|
||||||
max = strlen(options[i]);
|
max = strlen(options[i]);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ void drawMenu(char *options[], int lenght) {
|
||||||
|
|
||||||
drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4);
|
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);
|
goToCoords((columns - max - 4) / 2 + 2, 4 + i);
|
||||||
printf("%s", options[i]);
|
printf("%s", options[i]);
|
||||||
}
|
}
|
||||||
|
@ -174,4 +175,4 @@ void menu()
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue