g
This commit is contained in:
parent
e09fa3b54e
commit
2ee3f9b481
@ -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);
|
char* result = fgets(buffer, size, stdin);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
||||||
buffer[strcspn(buffer, "\n")] = '\0';
|
buffer[strcspn(buffer, "\n")] = '\0';
|
||||||
}
|
}
|
||||||
return result;
|
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;
|
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;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user