In this code, the second do while loop is not working properly. Whenever I press y to enter again. It just repeats the Enter again [y/n] option again and again instead of starting from 2nd do-while loop. I don't want it to give me an option to enter id card number again and again.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE *fr = fopen("file.csv", "r");
char string[200], toFind[200], opt;
int err = 0;
char *line1 = NULL;
do {
printf("Enter ID Card number: ");
scanf("%s", toFind);
if (strlen(toFind) != 13) {
break;
}
do { // This loop is not working properly
{
err = 1;
while (fgets(string, 200, fr)) {
line1 = strtok(string, "\n");
printf("%s\n", line1);
err = 0;
}
}
printf("Repeat again [y/n]: ");
scanf("%s", &opt);
} while (opt == 'y');
} while(err);
return 0;
}