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

This is a discussion on Please help I suck at programing I probably have a brace wrong! within the C Programming forums, part of the General Programming Boards category; Code: [#include <stdio.h> #include <stdlib.h> struct node_t { int data; struct node_t* next; }; struct node_t* node_init(int data) { struct ...

  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
    2,370
    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
    5,827
    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%.

  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
    5,827
    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%.

  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, 06: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. Why america sucks
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 138
    Last Post: 04-10-2002, 11:57 PM
  4. Perhaps someone can see where i am wrong?
    By laree in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 11:47 PM
  5. what I'm I doing wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 02-03-2002, 01:46 AM

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