funguje
This commit is contained in:
parent
3eb4c202d2
commit
e9b1cca2e4
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user