This commit is contained in:
Bohdan Kapliuk 2024-04-25 23:05:00 +03:00
parent 70170f4869
commit b48a9bc157

View File

@ -9,15 +9,22 @@ int main() {
char name[50]; char name[50];
char **prihlasky = NULL; char **prihlasky = NULL;
int counter = 0; int counter = 0;
prihlasky = (char **)malloc(max * sizeof(char *));
if (scanf("%d", &max) != 1 || max <= 0) { if (scanf("%d", &max) != 1 || max <= 0) {
puts("Nespravny vstup"); puts("Nespravny vstup");
return 1; return 1;
} }
prihlasky = (char **)malloc(max * sizeof(char *));
fgets(name, 50, stdin); fgets(name, 50, stdin);
while (fgets(name, 50, stdin) && name[0] != '\n') { while (fgets(name, 50, stdin) && name[0] != '\n') {
prihlasky[counter] = strdup(name); int checker = 0;
counter++; for(int i = 0;i < counter && i < max;i++){
if(strcmp(prihlasky[i], name) == 0)
checker = 1;
}
if(checker == 0){
prihlasky[counter] = strdup(name);
counter++;
}
} }
qsort(prihlasky, counter, sizeof(char *), compare); qsort(prihlasky, counter, sizeof(char *), compare);
puts("Prijati studenti:"); puts("Prijati studenti:");