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