Initialization

This commit is contained in:
Kozar 2024-03-21 17:34:39 +01:00
parent 63d0ca3727
commit d091201320

View File

@ -27,6 +27,7 @@ int compare(const void *a, const void *b) {
int main() {
struct student students[SIZE];
int size = 0;
int successful_lines = 0; // Counter for successful lines read
// read student data from standard input
while (1) {
@ -43,13 +44,16 @@ int main() {
// parse the string and extract number of votes and student name
int votes;
char name[SIZE];
// Attempt to parse the input line
if (sscanf(line, "%d %[^\n]", &votes, name) != 2) {
// Error: Unable to parse input line
printf("Nepodarilo nacitat nic\n");
return 1; // Exit with error code
if (successful_lines >= 1){
break;
}
else{
printf("Nepodarilo nacitat nic")
}
}
successful_lines++;
// check if this student already exists
int found = 0;