123
This commit is contained in:
parent
f7323ac3c7
commit
29911df6d3
@ -20,6 +20,7 @@ int find_student(const char* name){
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int compare(const void* a, const void* b) {
|
||||
struct student* s1 = (struct student*)a;
|
||||
struct student* s2 = (struct student*)b;
|
||||
@ -36,15 +37,27 @@ int compare(const void* a, const void* b) {
|
||||
int main() {
|
||||
char line[SIZE];
|
||||
memset(databaza, 0, sizeof(databaza));
|
||||
|
||||
while (fgets(line, SIZE, stdin)) {
|
||||
char* end = NULL;
|
||||
int votes = strtol(line, &end, 10);
|
||||
if (votes == 0 && end == line) {
|
||||
printf("Chyba: Neplatny format vstupu!\n");
|
||||
continue;
|
||||
}
|
||||
while (*end == ' ') {
|
||||
end++;
|
||||
}
|
||||
if (*end == '\0' || *end == '\n') {
|
||||
printf("Chyba: Neplatny format - chyba meno!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
char name[SIZE];
|
||||
memset(name, 0, SIZE);
|
||||
strncpy(name, end + 1, strlen(end + 1) - 1);
|
||||
strncpy(name, end, SIZE - 1);
|
||||
name[strcspn(name, "\n")] = '\0';
|
||||
|
||||
int id = find_student(name);
|
||||
if (id < 0) {
|
||||
if (size >= SIZE) {
|
||||
@ -55,9 +68,7 @@ int main() {
|
||||
strncpy(databaza[size].name, name, SIZE - 1);
|
||||
databaza[size].votes = votes;
|
||||
size++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
databaza[id].votes += votes;
|
||||
}
|
||||
}
|
||||
@ -75,3 +86,4 @@ int main() {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user