pvjc22/du6/program.c
Yaroslav Orlianskyi 85683e167c funguje
2022-04-21 20:48:59 +02:00

82 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

nclude <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 с = 0; с < 30; с++) {
if (isalpha(r[с])) {
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;
}