diff --git a/cv5/program.c b/cv5/program.c index 5d80a46..10a6f3e 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -2,6 +2,7 @@ #include #include #include +#include #define SIZE 100 #define MY_ERROR_OUTPUT stderr // chybovy vystup @@ -24,13 +25,13 @@ int compare_students(const void *a, const void *b) { return strcmp(student_a->name, student_b->name); } -int check_and_parse_line(char *line, int *votes, char *name) { +int check_line(char *line, int *votes, char *name) { // najdenie prvej medzery v retazci - char *space_pos = strchr(line, ' '); + char *space = strchr(line, ' '); // kontrola, ci sa nasla medzera - if (space_pos == NULL) { + if (space == NULL) { return 0; // neplatny riadok } @@ -40,9 +41,13 @@ int check_and_parse_line(char *line, int *votes, char *name) { if (*votes == 0) { return 0; // premena sa nepodarila } - + + //preskocenie inych znakov na zaciatku nez cislo + while (*end != '\0' && !isdigit(*end)) { + end++; //posuvam sa na dalsi znak v retazci + } // nastavenie ukazovatela name na miesto za prvou medzerou - char *name_start = space_pos + 1; + char *name_start = space + 1; // nacitanie mena memset(name, 0, SIZE); // vynulovanie pomocneho pola pre meno @@ -88,7 +93,7 @@ int main() { break; } - if (check_and_parse_line(line, &votes, name) == 0) { + if (check_line(line, &votes, name) == 0) { printf("Neplatny format"); continue; // preskoci riadok a nacita dalsi } diff --git a/cv5/program.exe b/cv5/program.exe index 13371e3..ea547dd 100644 Binary files a/cv5/program.exe and b/cv5/program.exe differ