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); }