diff --git a/cv5/program.c b/cv5/program.c index bc93527..0d85018 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -34,12 +34,20 @@ int main() { char buffer[MAX_BUFFER_LENGTH]; while (fgets(buffer, sizeof(buffer), stdin) != NULL) { // Načítajte počet hlasov a meno študenta - int votes; - char name[MAX_NAME_LENGTH]; - if (sscanf(buffer, "%d %99s", &votes, name) != 2) { + char *token = strtok(buffer, " "); + if (token == NULL) { fprintf(stderr, "Chyba: Neplatný formát vstupu.\n"); return 1; } + int votes = atoi(token); + + token = strtok(NULL, "\n"); + if (token == NULL) { + fprintf(stderr, "Chyba: Neplatný formát vstupu.\n"); + return 1; + } + char name[MAX_NAME_LENGTH]; + strncpy(name, token, MAX_NAME_LENGTH); // Uložte študenta do poľa strncpy(students[num_students].name, name, MAX_NAME_LENGTH);