From 2d1dead1b9b8abef5cfbe53cf321717684658192 Mon Sep 17 00:00:00 2001 From: ak643du Date: Mon, 22 Apr 2024 14:01:17 +0200 Subject: [PATCH] Initialization --- cv10/program.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cv10/program.c diff --git a/cv10/program.c b/cv10/program.c new file mode 100644 index 0000000..51c1989 --- /dev/null +++ b/cv10/program.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#define SIZE 100 + +int compare(const void* arg1, const void* arg2) { + char* s1 = *((char**)arg1); + char* s2 = *((char**)arg2); + return strcmp(s1, s2); +} + +int main() { + char* pole_smernikov[SIZE]; + memset(pole_smernikov, 0, SIZE * sizeof(char*)); + + char line[SIZE]; + memset(line, 0, SIZE); + + int pocet_mien_v_poli = 0; + + while (fgets(line, SIZE, stdin) != NULL && strlen(line) > 0) { + int found = 0; + for (int i = 0; i < pocet_mien_v_poli; i++) { + if (memcmp(pole_smernikov[i], line, strlen(line)) == 0) { + found = 1; + break; + } + } + + if (!found) { + pole_smernikov[pocet_mien_v_poli] = malloc(strlen(line) + 1); + memcpy(pole_smernikov[pocet_mien_v_poli], line, strlen(line) + 1); + pocet_mien_v_poli++; + } + + memset(line, 0, SIZE); + } + + qsort(pole_smernikov, pocet_mien_v_poli, sizeof(char*), compare); + + printf("Prijati studenti:\n"); + for (int i = 0; i < pocet_mien_v_poli; i++) { + printf("%s", pole_smernikov[i]); + } + + for (int i = 0; i < pocet_mien_v_poli; i++) { + free(pole_smernikov[i]); + } + + return 0; +} \ No newline at end of file