pvjc22/du6/program.c
Yaroslav Orlianskyi 484014a1bc SAD
2022-04-21 21:16:17 +02:00

82 lines
1.6 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char database[200][30];
char string[30];
int error = 0;
int count = 0;
int i = 0;
memset(database, 0, sizeof(database));
memset(string, 0, 30);
char *r;
r = fgets(string, 1000, stdin);
if (r == NULL)
return 0;
sscanf(string, "%d", &count);
if(strlen(r) == 1 || count < 1) {
puts("Nespravny vstup");
return 0;
}
for (int c = 0; c < 30; c++) {
if (isalpha(r[c])) {
error = 1;
break;
}
}
if (error != 0) {
puts("Nespravny vstup");
return 0;
}
while (strlen(r) > 1) {
memset(string, 0, 30);
r = fgets(string, 30, stdin);
if (r == NULL)
break;
error = 0;
for (int j = 0; j < 200; j++) {
if (strcmp(database[j], string) == 0) {
error = 1;
break;
}
}
if (error == 0 && strlen(r) > 1) {
strcpy(database[i], r);
i++;
}
}
if (i == 0) {
puts("Ziadne prihlasky");
}
for (int j = 0; j < i; j++) {
for (int j = 0; j < i; j++) {
if (strcmp(database[j], database[j]) < 0) {
char buffer[30];
memset(buffer, 0, sizeof(buffer));
strcpy(buffer, database[j]);
strcpy(database[j], database[j]);
strcpy(database[j], buffer);
}
}
}
puts("Prijati studenti:");
for (int j = 0; j < i; j++) {
if (j == count) {
puts("Neprijati studenti:");
}
printf("%s", database[j]);
}
return 0;
}