C Programming - Beginner's Help

Discussion in 'Mac Programming' started by NeoPharoah, Oct 1, 2009.

  1. NeoPharoah macrumors newbie

    Oct 1, 2009
    Hey there, I'm real new to C programming and I have been getting this error every time i try to compile my code.

    eg1.c: In function 'main':
    eg1.c:10: error: parse error before "pid_t"

    I have searched google and it says it has something to do with a semi colon missing but I have checked this simple code and nothing seems out of place. I need some help as my experience in programming c is very limited.

    Here is the code below

    /*pidemo.c - Displays process indentification information */
    #include <stdio.h>
    #include <sys/types.h> /* System specific types such as pid_t (below) */
    int main()
        pid_t   my_pid;
        my_pid = getpid();
        printf("Hi! I am process #%d\n",pid_t);
    Thanks for any help whatsoever
  2. pilotError macrumors 68020


    Apr 12, 2006
    Long Island
    I think you need

    #include <unistd.h>

    in the headers.

    My SDK uninstalled with the upgrade to SL, so I wasn't able to try it.
  3. electroshock macrumors 6502a


    Sep 7, 2009
    Nah -- doesn't need that header file. I do see the problem, though. BTW, you can reinstall Xcode by popping in your SL DVD, going to the Optional Installs folder, and installing Xcode.

    pid_t is just a type. You need to replace that with my_pid (the actual variable) then it should compile.

    Think of it this way: printf wants to know what's in your wallet (variable) rather than what kind of wallet (type) you have.
  4. kainjow Moderator emeritus


    Jun 15, 2000
    That last line should be:
    printf("Hi! I am process #%d\n",[color=red][b]my_pid[/b][/color]);
  5. NeoPharoah thread starter macrumors newbie

    Oct 1, 2009
    Thanks alot, got it to work. Can't believe I didn't notice that. Thanks once again for the help

Share This Page