Thread: Please help I suck at programing I probably have a brace wrong!

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Talking Please help I suck at programing I probably have a brace wrong!

    Code:
    [#include <stdio.h>
    #include <stdlib.h>
    
    struct node_t {
        int data;
        struct node_t* next;
    };
    
    struct node_t* node_init(int data) {
        struct node_t* res=malloc(sizeof(struct node_t));\
        res->data=data;
        res->next=0;
        return res;
    }
    
    void nod_free(struct node_t* node){
        free(node);
    }
    
    struct stack_t {
        struct node_t* top;
    };
    
    struct stack_t* stack_init() {
        struct stack_t* res=malloc(sizeof(struct stack_t));
        res->top=0;
        return res;
    }
    int stack_is_empty(struct stack_t* st) {
        return st->top==0;
    }
    
    void stack_push(struct stack_t* st,int data) {
        struct node_t* n=node_init(data);
        n->next=st->top;
        st->top=n;
    
    int main() {
        struct stack_t* stack_init();
    printf("stack is empty?=%d\n", stack_is_empty(st));
        stack_push(st,10);
        stack_push(st,20);
    printf("stack is empty?=%d\n", stack_is_empty(st));
    
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Svetlin61 View Post
    Code:
    [#include <stdio.h>
    
        struct node_t* res=malloc(sizeof(struct node_t));\
       
    
    void stack_push(struct stack_t* st,int data) {
        struct node_t* n=node_init(data);
        n->next=st->top;
        st->top=n;
    Missing Brace
    Tim S.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The is an opening square bracket at the first character.

    The backslash in node_init() is not needed.

    There is no closing brace on your stack_push() function.

    If you had applied a little effort, you could have worked it out yourself from the output of your compiler. Tthe only thing to remember is that, if you get an error message, you may need to scroll UP to find the cause. Difficulty level: about 0.5 out of 10.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Unhappy Didn't work u guys!!!

    Did any of you run the program??? The error it gives me is : filename.c:47: error: expected declaration or statement at end of input. And since I suck at this I don't know what that means.
    After fixing what you said its the same freaking error ,please help.Oh and there weren't any of the mistakes you said before.I mean that those weren't really mistakes check the whole program. And please run it.
    Last edited by Svetlin61; 03-20-2011 at 12:53 AM.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Svetlin61 View Post
    Did any of you run the program???
    You can't run it, it doesn't compile.
    Quote Originally Posted by Svetlin61 View Post
    After fixing what you said its the same freaking error ,please help
    So post your new code, and your errors and highlight the section it's talking about.
    Quote Originally Posted by Svetlin61 View Post
    Oh and there weren't any of the mistakes you said before. I mean that those weren't really mistakes
    Yes they were. We don't just randomly point at your code and try to trick you into thinking something is an error when it isn't.
    Quote Originally Posted by Svetlin61 View Post
    check the whole program. And please run it.
    You can't run it, it doesn't compile.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Not interested in running or even compiling your program. If there are errors, it is your job to interpret the error messages and then to find them. The most you get here is some advice and hints on where to look - not actually doing the work that you need to do.

    If you suck, you need to apply effort to remedy that, rather than expecting others to do your work for you. Otherwise, you will continue to suck.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Unhappy Help me!

    Now I really don't mean to be rude I just can't find my mistake. Its the same error since the very beginning and its not changing with any of the stuff you tell me.
    Code:
     #include <stdio.h>
    #include <stdlib.h>
    
    struct node_t {
        int data;
        struct node_t* next;
    };
    
    struct node_t* node_init(int data) {
        struct node_t* res=malloc(sizeof(struct node_t));\
        res->data=data;
        res->next=0;
        return res;
    }
    
    void nod_free(struct node_t* node){
        free(node);
    }
    
    struct stack_t {
        struct node_t* top;
    };
    
    struct stack_t* stack_init() {
        struct stack_t* res=malloc(sizeof(struct stack_t));
        res->top=0;
        return res;
    }
    int stack_is_empty(struct stack_t* st) {
        return st->top==0;
    }
    
    void stack_push(struct stack_t* st,int data) {
        struct node_t* n=node_init(data);
        n->next=st->top;
        st->top=n;
    }
    int main() {
        struct stack_t* stack_init();
    printf("stack is empty?=%d\n", stack_is_empty(st));
        stack_push(st,10);
        stack_push(st,20);
    printf("stack is empty?=%d\n", stack_is_empty(st));
    
        return 0;
    }
    args.c:47: error: expected declaration or statement at end of input

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It doesn't give that error. It gives an error because you don't have anything called 'st' prior to you using it in main. So you tell us to run your code but you aren't even running it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. similarity between programing languages
    By c_weed in forum Tech Board
    Replies: 6
    Last Post: 11-24-2010, 07:02 AM
  2. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM
  3. Perhaps someone can see where i am wrong?
    By laree in forum C++ Programming
    Replies: 6
    Last Post: 02-13-2002, 12:47 AM
  4. what I'm I doing wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-03-2002, 02:46 AM