funguje
This commit is contained in:
parent
3eb4c202d2
commit
e9b1cca2e4
@ -34,12 +34,20 @@ int main() {
|
|||||||
char buffer[MAX_BUFFER_LENGTH];
|
char buffer[MAX_BUFFER_LENGTH];
|
||||||
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
|
||||||
// Načítajte počet hlasov a meno študenta
|
// Načítajte počet hlasov a meno študenta
|
||||||
int votes;
|
char *token = strtok(buffer, " ");
|
||||||
char name[MAX_NAME_LENGTH];
|
if (token == NULL) {
|
||||||
if (sscanf(buffer, "%d %99s", &votes, name) != 2) {
|
|
||||||
fprintf(stderr, "Chyba: Neplatný formát vstupu.\n");
|
fprintf(stderr, "Chyba: Neplatný formát vstupu.\n");
|
||||||
return 1;
|
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
|
// Uložte študenta do poľa
|
||||||
strncpy(students[num_students].name, name, MAX_NAME_LENGTH);
|
strncpy(students[num_students].name, name, MAX_NAME_LENGTH);
|
||||||
|
Loading…
Reference in New Issue
Block a user