Update du4/program.c

This commit is contained in:
Martin Kačmár 2025-03-19 18:38:09 +00:00
parent 4bbb299f45
commit c2e16f54da

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_NAME 100
#define MAX_ENTRIES 100
@ -49,16 +50,20 @@ int main() {
int has_data = 0;
while (fgets(line, sizeof(line), stdin)) {
// Preskočí prázdne riadky
if (strlen(line) <= 1) continue;
if (sscanf(line, "%d %[^\n]", &votes, name) != 2 || votes < 0) {
break;
continue; // Namiesto prerušenia len ignoruje neplatné riadky
}
Student *student = find_or_add(name);
if (student) student->votes += votes;
has_data = 1;
}
if (!has_data) {
printf("Chyba: Nebol zadany platny vstup.\n");
printf("Nepodarilo nacitat nic\n");
return 1;
}