Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: C programming stacks

  1. #1
    Join Date
    Nov 2012
    Beans
    43

    C programming stacks

    Hello. Can someone please write a C program that has the following characteristics:

    1) Uses a LIFO stack to store integers
    2) User can enter values(PUSH)
    3) User can remove values(POP)
    4) Stack is printed to the screen when the program starts and each time PUSH or POP is performed.
    5) The top of the stack contains the newest element, the bottom contains the oldest element.

    I want the program to actually print out something that looks like a stack. Something like this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    int stackElement=9;
    int i;
    
    for(i=0; i<10; i++)
    {
    printf("+------------+\n");
    printf("|     %d     |\n",stackElement);
    printf("|            |\n");
    printf("+------------+\n");
    stackElement--;
    }
    
    return 0;
    }
    Note: The output of my program is nicely aligned to make a rectangle.

    This isn't homework. I want to learn stacks on my own and I think a program like this would help me. Please use as few functions and pointers as possible.

  2. #2
    Join Date
    Feb 2009
    Beans
    1,469

    Re: C programming stacks

    Quote Originally Posted by binaryperson View Post
    Hello. Can someone please write a C program
    Yes, someone can. I can, in fact, for a reasonable hourly rate (two hour minimum). But you're not likely to get an uninteresting program like this for free, even if it's not homework.

    This isn't homework. I want to learn stacks on my own and I think a program like this would help me. Please use as few functions and pointers as possible.
    Wouldn't you learn more by doing it yourself?

  3. #3
    Join Date
    Nov 2012
    Beans
    43

    Re: C programming stacks

    I was thinking of reverse engineering the program and then trying to write a FIFO stack on my own followed by other abstract data types. I am only familiar with arrays and structures as far as data types go. Everyone needs to be lent a hand, at the beginning, before they get the hang of things. By the way, how much do you charge per hour? Do you offer any help, advice or suggestions without the expectation of monetary return?
    Last edited by binaryperson; March 8th, 2013 at 01:08 AM.

  4. #4
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: C programming stacks

    Quote Originally Posted by trent.josephsen View Post
    Wouldn't you learn more by doing it yourself?
    I wonder what will be the answer you'll get?

    Assuming that there's going to be one.

  5. #5
    Join Date
    Nov 2012
    Beans
    43

    Re: C programming stacks

    No I wouldn't learn more if I have no idea where to start. If someone doesn't help me I will just not learn stacks and that will be the end of it. I don't have to learn stacks, I just wanted to.

  6. #6
    Join Date
    Nov 2012
    Beans
    43

    Re: C programming stacks

    Thanks for absolutely nothing.

  7. #7
    Join Date
    Aug 2011
    Location
    Melbourne, Australia.
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: C programming stacks

    Quote Originally Posted by binaryperson View Post
    Thanks for absolutely nothing.

    Trying to do it yourself is always the best option -

    You can always ask for help if you come up with a deadend -
    PopularPages: A very handy Documentation Search Tool used by many.
    PopularPages Wiki Thread
    My New Blog

  8. #8
    Join Date
    Apr 2012
    Beans
    7,256

    Re: C programming stacks

    IIRC Kernighan and Ritchie develop a simple implementation of a stack-based RP calculator in their original 'The C Programming Language' book - maybe that would be a good starting point?

  9. #9
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: C programming stacks

    Quote Originally Posted by binaryperson View Post
    Thanks for absolutely nothing.
    I think that what trent.josephsen meant was something like
    “Give a man a fish, and you’ll feed him for a day. Teach a man to fish, and you’ve fed him for a lifetime.”
    So as a sort of a fishing rod, you can start here:
    Stack - Array Implementation
    Data Structures: Stacks ( with C Program source code)

  10. #10
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: C programming stacks

    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •