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