Code link: https://godbolt.org/z/dxn38f53h
Trying to replicate/understand this post: https://stackoverflow.com/a/47587807/15603477.
The issue is that teams can be duplicated.
Trying to find a way that check sscanf input value is unique compare to all of previous input (ignore default value 0).
Expected result: when stdin input (team number) value is duplicated make the function input reset to "begin":
printf("\nEnter your team: ");
while x>=1 block that part is so far what I tried.
void input(int a[NROW][NCOL], int teams[NROW])
{
int x, y;
for (x = 0; x < NROW; x++) {
for (;;) {
int rtn;
printf("\nEnter your team: ");
rtn = scanf("%d", &teams[x]);
while (x >= 1) {
printf("x=\t%d\n", x);
for (int j = 1; j <= x; j++) {
if (teams[j] == teams[j - 1]) {
fprintf(stderr,"duplicate team number.\n");
// x = x + 1;
printf("x=%d\n", x);
break;
} else {
break;
}
}
break;
}
if (rtn == 1)
break;
else if (rtn == EOF) {
fprintf(stderr, "user canceled input.\n");
exit(EXIT_FAILURE);
}
fprintf(stderr,"error: invalid input.\n");
empty_stdin();
}
for (y = 0; y < NCOL; y++) {
for (;;) {
int rtn;
printf("Enter team[%d] score [%d]: ",teams[x],y+1);
rtn = scanf("%d", &a[x][y]);
if (rtn == 1)
break;
else if (rtn == EOF) {
fprintf(stderr, "user canceled input.\n");
exit(EXIT_FAILURE);
}
fprintf(stderr, "error: invalid input.\n");
empty_stdin();
}
}
}
}