Thread: help newbie compile program!

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    4

    help newbie compile program!

    hello. i am trying to compile this c program but am encountering errors... not familiar with c logic enough to fix it. can you try to compile and fix, or recognize error? thanks
    (this code is supposed to start process, and execute, please don't alter logic. help me fix syntax!)
    PS: i've been getting lots of error msgs but after fixing them I still am left with:

    line 1: Parse Error, expecting `SEP'
    '{ int fork(), value'

    Can anyone help? thanks!

    *begin code*

    {
    int fork(), value;

    value = fork();
    value = fork();
    printf("in main: value * %d\n", value);

    return 0;

    }

    //
    int fork(void);
    int main()
    {
    if (fork() == 0); /*child process*/
    {
    printf("hello there \n");
    return;
    }
    else /*parent process*/
    printf("good bye\n");
    printf("how are you doing?\n")
    return 0;

    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please post your code in [code][/code] bbcode tags. Especially since you are looking for help on correcting syntax errors, post complete code that you think is syntactically correct (i.e., do not comment out parts with things like "*begin code*").
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    ok sorry.

    i remember that in the future. in the meanwhile; i don't suppose you could help me with my syntax error?


  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    Code:
    {
    int fork(), value;
    
    value = fork();
    value = fork();
    printf("in main: value * %d\n", value);
    
    return 0;
    
    }
    
    int fork(void);
    int main()
    {
    if (fork() == 0); /*child process*/
    {
    printf("hello there \n");
    return;
    }
    else /*parent process*/
    printf("good bye\n");
    printf("how are you doing?\n")
    return 0;
    
    }

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You can edit your original post

    Anyway, at a glance you are missing a terminating semi-colon on this line:
    Code:
    printf("how are you doing?\n")
    EDIT:
    Ah, you need to indent your code as well.

    However, why do you have a block of code in the middle of nowhere (i.e., outside of a function)?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    4
    ok - i put the semicolon i am still getting the syntax error
    Code:
    line 1: Parse Error, expecting `SEP'
    '{ int fork(), value'
    also; i am trying to show a child process and parent process.. this is going to eventually be a bigger program but i need to get these initial processes working first lol any help getting this executable will be swell!

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, why do you have this block of code?
    Code:
    {
        int fork(), value;
    
        value = fork();
        value = fork();
        printf("in main: value * %d\n", value);
    
        return 0;
    }
    It looks like it should be in a function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    And what is the point of assigning value twice?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance and program structure planning please help a newbie
    By ninjacookies in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2005, 12:18 PM
  2. newbie: steps to create and compile c program in SUSE
    By gemini_shooter in forum Linux Programming
    Replies: 12
    Last Post: 06-22-2005, 06:35 PM
  3. compile program?
    By Goosie in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2005, 02:26 PM
  4. newbie needs help with C++ program
    By cyba in forum C++ Programming
    Replies: 9
    Last Post: 06-25-2004, 02:41 AM
  5. How To Embed Data In Program While Compile?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2002, 10:14 AM