Help find the bug

Discussion in 'C' started by mmondal71, May 30, 2010.

  1. mmondal71

    mmondal71 New Member

    Joined:
    May 25, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. singh_r85

    singh_r85 New Member

    Joined:
    May 25, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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));
                  }
    }
    
    /
     
  3. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice