C programming

This is a discussion on C programming within the C Programming forums, part of the General Programming Boards category; hi friends i am stuck in a stack program . in my program pop operation is not working properly. it ...

  1. #1
    anu
    anu is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    Question C programming

    hi friends

    i am stuck in a stack program .

    in my program pop operation is not working properly.

    it removes top element first time but second time it shows error. perhaps free is not working.

    i am attaching my program. any help would be appreciated.


    new user
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    > struct stack *pop (struct stack * tos);

    This should be declared as
    int pop (struct stack * tos);

    You want to return the top element from the stack.

    You need to think about how to return a modified stack from this function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21