This commit is contained in:
Macko 2024-04-15 22:09:20 +02:00
parent 0c730c6c4f
commit f2064443b2

View File

@ -5,24 +5,22 @@
#define SIZE 100
int compare(const void* arg1, const void* arg2) {
const char* s1 = *((const char**)arg1);
const char* s2 = *((const char**)arg2);
char* s1 = *((char**)arg1);
char* s2 = *((char**)arg2);
return strcmp(s1, s2);
}
int main() {
char* pole_smernikov[SIZE] = {NULL}; // Inicializujeme všetky smerníky na NULL
char* pole_smernikov[SIZE];
memset(pole_smernikov, 0, SIZE * sizeof(char*));
int pocet_mien_v_poli = 0;
char line[SIZE];
while (fgets(line, SIZE, stdin) != NULL) {
int pocet_znakov = strlen(line);
if (pocet_znakov == 1 && line[0] == '\n') // Skončiť na prázdnom riadku
break;
// Odstrániť koniec riadka
if (line[pocet_znakov - 1] == '\n')
line[--pocet_znakov] = '\0';
line[strcspn(line, "\n")] = 0; // Remove the newline character
int pocet_znakov = strlen(line) + 1; // Include the null terminator
if (pocet_znakov == 1) // Skip empty lines
continue;
// Kontrola duplicít
int found = 0;
@ -32,12 +30,8 @@ int main() {
break;
}
}
if (!found && pocet_mien_v_poli < SIZE) {
pole_smernikov[pocet_mien_v_poli] = malloc(pocet_znakov + 1);
if (pole_smernikov[pocet_mien_v_poli] == NULL) {
fprintf(stderr, "Chyba pri alokácii pamäte\n");
exit(EXIT_FAILURE);
}
if (!found) {
pole_smernikov[pocet_mien_v_poli] = malloc(pocet_znakov);
strcpy(pole_smernikov[pocet_mien_v_poli], line);
pocet_mien_v_poli += 1;
}
@ -48,10 +42,7 @@ int main() {
// Výpis prijatých a neprijatých študentov
int max_students;
if (scanf("%d", &max_students) != 1) { // Kontrola úspešnosti načítania
fprintf(stderr, "Chyba pri načítaní počtu študentov\n");
exit(EXIT_FAILURE);
}
scanf("%d", &max_students);
printf("Prijati studenti:\n");
for (int i = 0; i < max_students && i < pocet_mien_v_poli; i++) {