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