Initialization
This commit is contained in:
parent
a339ad8387
commit
ae1b4851e9
@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define SIZE 100
|
||||
|
||||
@ -44,11 +43,11 @@ int main() {
|
||||
// parse the string and extract number of votes and student name
|
||||
int votes;
|
||||
char name[SIZE];
|
||||
if (sscanf(line, "%d %s", &votes, name) != 2 || !isdigit(name[0])) {
|
||||
if (sscanf(line, "%d %[^\n]", &votes, name) != 2) {
|
||||
// error, input was not in expected format
|
||||
// print error message and continue to next line
|
||||
// print error message and exit
|
||||
fprintf(stderr, "Error: invalid input format\n");
|
||||
continue;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// check if this student already exists
|
||||
@ -74,7 +73,7 @@ int main() {
|
||||
qsort(students, size, sizeof(struct student), compare);
|
||||
|
||||
// print the results
|
||||
printf("Results:\n");
|
||||
printf("Vysledky:\n");
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%d %s\n", students[i].votes, students[i].name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user