"when I call one goto like name1 with if else it all the values of gotos. like all the name1 name2 name3 name4. Help!!!"
It seems that you misunderstanding the use of goto
. A goto
label doesn´t specify a certain group of statements (compound statement/block) or just a single statement to it like it is f.e. to a particular condition match to a if
/elseif
chain or a switch
/case
statement.
The goto name1
statement just let you jump to the position of the label name1
. Nothing more, nothing less.
If you want to achieve what you described, use a switch
like:
#include<stdio.h>
int main(){
int num;
printf("Name number\n");
scanf("%d",&num);
switch(num) {
case 1:
printf("M");
break;
case 2:
printf("A");
break;
case 3:
printf("I");
break;
case 4:
printf("Y");
break;
default:
break;
}
return 0;
}
Note that the use of goto
as you did is commonly deprecated.
You should take a look at these posts:
Is it ever advantageous to use 'goto' in a language that supports loops and functions? If so, why?
GOTO still considered harmful?