diff --git a/cv10/program.c b/cv10/program.c index e69de29..90bb99c 100644 --- a/cv10/program.c +++ b/cv10/program.c @@ -0,0 +1,34 @@ +#include +#include +#include +int compare(const void *a, const void *b) { + return strcmp(*(const char **)a, *(const char **)b); +} +int main() { + int max; + char name[50]; + char **prihlasky = NULL; + int counter = 0; + prihlasky = (char **)malloc(max * sizeof(char *)); + if (scanf("%d", &max) != 1 || max <= 0) { + puts("Nespravny vstup"); + return 1; + } + fgets(name, 50, stdin); + while (fgets(name, 50, stdin) && name[0] != '\n') { + prihlasky[counter] = strdup(name); + counter++; + } + qsort(prihlasky, counter, sizeof(char *), compare); + puts("Prijati studenti:"); + for (int i = 0; i < max && i < counter; i++) { + printf("%s", prihlasky[i]); + } + if (counter > max) { + puts("Neprijati studenti:"); + for (int i = max; i < counter; i++) { + printf("%s", prihlasky[i]); + } + } + return 0; +}