hai, i have developed a c-code to push integers into a stack (an array). in the program there are three inputs which has to be given through keyboard. the inputs are "choice", "option","S_R_NO" and "i" all are defined as "int". now when the inputs given are int type the program behaviour is as required. but when the input given are char type the program is executing infinite loop.i could not understand this behaviour and i am unable to start. the code is developed on turbo-c and it is executiable. can any one help me in finnding the bug and tell me the better way of doing.
Code: */ void push(int *stk) { register int i,j; top+=1; if(top==SIZE){ printf("\nOverflow of the stack");top-=1; } else { printf("\nEnter the element you want to push: "); scanf("%d",&i); *(stk+top)=i; printf("now the stack is:"); for(j=0;j<=top;j++) printf("\nelement at <%d> is <%d>",j,*(stk+j)); } } /
runtime problems: 1) first round input: if a char is entered for "i" program terminating without asking for the next value of "option". 2) after first round of input: if char is given as input for any of the variables "choice", "option","S_R_NO" or "i" the program is executing infiniteloop.