Hi, i have this project where the size, 2d array of size n is scanned from a file; asks for the vertex pairs from the command prompt until the user decides to stop inputting them. There is something wrong with my code because it skips the scanning of int variables from and to. Please help me and tell if you spot the problem. Thanks :)
int repeat() {
char rep;
printf("\n\n Proceed to Next Matrix? Y / N: ");
rep = getchar();
scanf("%c", &rep);
if(rep == 'Y')
return 1;
else if(rep == 'N')
return 0;
}
int operate() {
char reply;
printf("\n\n Test More Vertices Pairs? Y / N: ");
reply = getchar();
scanf("%c", &reply);
if(reply == 'Y')
return 1;
else if(reply == 'N');
return 0;
}
int main() {
int choice = 0, perform2=1,i,a,b, from , to;
char filename[200]="";
FILE * fileIn;
FILE * fOut;
do{
printf("\nChoose an option: \n"
"[1] Read Input\n"
"[2] Exit\n");
printf("Enter number: ");
scanf("%d",&choice);
printf("\n\n");
fOut = fopen("output.txt", "a");
if(choice == 1) {
printf("Enter File name: ");
scanf("%s", &filename);
if((fileIn = fopen(filename, "r")) == NULL) {
printf("File could not be opened. \n");}
else {
do{
fscanf(fileIn, "%d", &size);
int input[size][size];
for(a = 1; a<=size; a++) {
for(b=1; b<=size; b++) {
fscanf(fileIn, "%d", &input[a][b]);
}
}
fprintMatrix(input);
do{
printf("Enter vertex pair Ex.(4,3): ");
scanf("( %d , %d )", &from, &to);
}while(operate() ==1); //test more vertices?
fgetc(fileIn);
fprintf(fOut, "%s", "\nOutput:\n\n");
fclose(fOut);
perform2 = repeat();
}while((perform2 == 1) && !(feof(fileIn))); //Proceed to next matrix?
fclose(fileIn);
}
}
else if(choice == 2) {
printf("Exiting. \n");
break;
}
fclose(fileIn);
}while(choice != 2);
return 0;
}