From d0912013204b9c4328bb1f4b919d478fef6ee17b Mon Sep 17 00:00:00 2001 From: ak643du Date: Thu, 21 Mar 2024 17:34:39 +0100 Subject: [PATCH] Initialization --- cv5/program.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index 2f4dce4..1df0f8f 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -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,14 +44,17 @@ 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; for (int i = 0; i < size; i++) { @@ -80,4 +84,4 @@ int main() { } return 0; -} \ No newline at end of file +}