diff --git a/cv5/program.c b/cv5/program.c index bba61b1..fce909c 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -21,13 +21,24 @@ struct student { }*/ -char* read_line(char* buffer, int size) { +/*char* read_line(char* buffer, int size) { char* result = fgets(buffer, size, stdin); if (result) { buffer[strcspn(buffer, "\n")] = '\0'; } return result; +}*/ + +int read_input(int* votes, char* name, int size) { + char line[SIZE]; + if (fgets(line, size, stdin) != NULL) { + + if (sscanf(line, "%d %s", votes, name) == 2) { + return 1; + } + } + return 0; } @@ -99,3 +110,24 @@ int compare_students(const void* p1, const void* p2) { return 0; }*/ +int main() { + struct student database[SIZE]; + int size = 0; + + int votes; + char name[SIZE]; + + + while (read_input(&votes, name, SIZE)) { + add_student(database, &size, name, votes); + qsort(database, size, sizeof(struct student), compare_students); + + + printf("Vysledky hlasovania:\n"); + for (int i = 0; i < size; ++i) { + printf("%d %s\n", database[i].votes, database[i].name); + } + } + + return 0; +}