Initialization

This commit is contained in:
Kozar 2024-03-21 16:54:33 +01:00
parent fa0f26fda1
commit a339ad8387

View File

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