This commit is contained in:
Matus Tokarcik 2024-03-21 23:45:54 +01:00
parent 4bfd81f296
commit 6cd148ed06
2 changed files with 11 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <ctype.h>
#define SIZE 100 #define SIZE 100
#define MY_ERROR_OUTPUT stderr // chybovy vystup #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); 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 // najdenie prvej medzery v retazci
char *space_pos = strchr(line, ' '); char *space = strchr(line, ' ');
// kontrola, ci sa nasla medzera // kontrola, ci sa nasla medzera
if (space_pos == NULL) { if (space == NULL) {
return 0; // neplatny riadok return 0; // neplatny riadok
} }
@ -40,9 +41,13 @@ int check_and_parse_line(char *line, int *votes, char *name) {
if (*votes == 0) { if (*votes == 0) {
return 0; // premena sa nepodarila 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 // nastavenie ukazovatela name na miesto za prvou medzerou
char *name_start = space_pos + 1; char *name_start = space + 1;
// nacitanie mena // nacitanie mena
memset(name, 0, SIZE); // vynulovanie pomocneho pola pre meno memset(name, 0, SIZE); // vynulovanie pomocneho pola pre meno
@ -88,7 +93,7 @@ int main() {
break; break;
} }
if (check_and_parse_line(line, &votes, name) == 0) { if (check_line(line, &votes, name) == 0) {
printf("Neplatny format"); printf("Neplatny format");
continue; // preskoci riadok a nacita dalsi continue; // preskoci riadok a nacita dalsi
} }

Binary file not shown.