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 <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
#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
}

Binary file not shown.