Can someone teach me how to get back to the main menu of the program without using goto.
such as this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
USER_MENU:
printf("\n[1] Encode File");
printf("\n[2] Decode File");
printf("\n[3] Exit\n");
printf("\nWhat do you want to do? ");
scanf("%d", &a);
switch(a) {
case 1:
//open file input.txt for reading
f_input = fopen("input.txt", "r");
if(f_input == NULL){
printf("\nFile input.txt was not found!!");
printf("\nFind the file and select again.\n");
printf("\n");
goto USER_MENU;
}
I want to learn how to substitute those goto's
BTW, The main menu of the program is the
printf("\n[1] Encode File");
printf("\n[2] Decode File");
printf("\n[3] Exit\n");
printf("\nWhat do you want to do? ");
//this int is just an example
int temp;
temp=1;
//while temp doesnt = 0
while(temp !=0)
printf("\n[1] Encode File");
printf("\n[2] Decode File");
printf("\n[3] Exit\n");
printf("\nWhat do you want to do? ");
scanf("%d", &a);
//first switch, which doesnt end the loop.
{
switch(a)
{
case 1: do stuff
break;
};
//second switch, which does end the loop because it makes the value of temp 0.
switch(b)
{
case 2: do stuff
temp = 0;
break;
};
}
thats the best as i can understand that you are wanting to do. i hope this helps! ^_^