1254
This commit is contained in:
parent
29911df6d3
commit
da94129580
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#define SIZE 100
|
#define SIZE 100
|
||||||
|
|
||||||
@ -25,32 +26,27 @@ int compare(const void* a, const void* b) {
|
|||||||
struct student* s1 = (struct student*)a;
|
struct student* s1 = (struct student*)a;
|
||||||
struct student* s2 = (struct student*)b;
|
struct student* s2 = (struct student*)b;
|
||||||
|
|
||||||
if (s1->votes > s2->votes) {
|
if (s1->votes > s2->votes) return -1;
|
||||||
return -1;
|
if (s1->votes < s2->votes) return 1;
|
||||||
} else if (s1->votes < s2->votes) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return strcmp(s1->name, s2->name);
|
return strcmp(s1->name, s2->name);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
memset(databaza, 0, sizeof(databaza));
|
memset(databaza, 0, sizeof(databaza));
|
||||||
|
|
||||||
while (fgets(line, SIZE, stdin)) {
|
while (fgets(line, SIZE, stdin)) {
|
||||||
char* end = NULL;
|
char* end;
|
||||||
int votes = strtol(line, &end, 10);
|
int votes = strtol(line, &end, 10);
|
||||||
if (votes == 0 && end == line) {
|
if (*end != ' ') {
|
||||||
printf("Chyba: Neplatny format vstupu!\n");
|
printf("Chyba: Neplatny format vstupu!\n");
|
||||||
continue;
|
return 1;
|
||||||
}
|
}
|
||||||
while (*end == ' ') {
|
|
||||||
end++;
|
end++;
|
||||||
}
|
|
||||||
if (*end == '\0' || *end == '\n') {
|
if (*end == '\0' || *end == '\n') {
|
||||||
printf("Chyba: Neplatny format - chyba meno!\n");
|
printf("Chyba: Neplatny format vstupu!\n");
|
||||||
continue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char name[SIZE];
|
char name[SIZE];
|
||||||
@ -62,9 +58,8 @@ int main() {
|
|||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
if (size >= SIZE) {
|
if (size >= SIZE) {
|
||||||
printf("Chyba: Databaza je plna!\n");
|
printf("Chyba: Databaza je plna!\n");
|
||||||
continue;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(databaza[size].name, name, SIZE - 1);
|
strncpy(databaza[size].name, name, SIZE - 1);
|
||||||
databaza[size].votes = votes;
|
databaza[size].votes = votes;
|
||||||
size++;
|
size++;
|
||||||
|
Loading…
Reference in New Issue
Block a user