From ae1b4851e9417a9303839ae5f0d42d21cbb5a28b Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 21 Mar 2024 16:57:37 +0100 Subject: [PATCH] Initialization --- cv5/program.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index d4016d9..3c66a1a 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -1,7 +1,6 @@ #include #include #include -#include #define SIZE 100 @@ -44,11 +43,11 @@ int main() { // parse the string and extract number of votes and student name int votes; char name[SIZE]; - if (sscanf(line, "%d %s", &votes, name) != 2 || !isdigit(name[0])) { + if (sscanf(line, "%d %[^\n]", &votes, name) != 2) { // error, input was not in expected format - // print error message and continue to next line + // print error message and exit fprintf(stderr, "Error: invalid input format\n"); - continue; + return 1; } // check if this student already exists @@ -74,7 +73,7 @@ int main() { qsort(students, size, sizeof(struct student), compare); // print the results - printf("Results:\n"); + printf("Vysledky:\n"); for (int i = 0; i < size; i++) { printf("%d %s\n", students[i].votes, students[i].name); }