pvjc22/du6/program.c

82 lines
1.6 KiB
C
Raw Normal View History

2022-04-21 18:50:35 +00:00
#include <stdio.h>
2022-04-21 18:48:59 +00:00
#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;
2022-04-21 19:07:27 +00:00
sscanf(string, "%d", &count);
if(strlen(r) == 1 || count < 1) {
2022-04-21 18:48:59 +00:00
puts("Nespravny vstup");
return 0;
}
2022-04-21 19:07:27 +00:00
for (int c = 0; c < 30; c++) {
if (isalpha(r[c])) {
2022-04-21 18:48:59 +00:00
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++;
}
}
2022-04-21 19:07:27 +00:00
if (i == 0) {
2022-04-21 18:48:59 +00:00
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;
}