This commit is contained in:
Sadchenko 2024-03-20 13:03:50 +01:00
parent 2ee3f9b481
commit b6c18a05ce

View File

@ -30,7 +30,7 @@ struct student {
return result;
}*/
int read_input(int* votes, char* name, int size) {
/*int read_input(int* votes, char* name, int size) {
char line[SIZE];
if (fgets(line, size, stdin) != NULL) {
@ -39,6 +39,24 @@ int read_input(int* votes, char* name, int size) {
}
}
return 0;
}*/
int read_input(int* votes, char* name, int size) {
char line[SIZE];
if (fgets(line, size, stdin) != NULL) {
char* space = strchr(line, ' ');
if (space != NULL) {
*votes = atoi(line);
strcpy(name, space + 1);
char* newline = strchr(name, '\n');
if (newline)
*newline = '\0';
return 1;
}
}
return 0;
}
@ -110,7 +128,7 @@ int compare_students(const void* p1, const void* p2) {
return 0;
}*/
int main() {
/*int main() {
struct student database[SIZE];
int size = 0;
@ -129,5 +147,28 @@ int main() {
}
}
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;
}