Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NeoPharoah

macrumors newbie
Original poster
Oct 1, 2009
2
0
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

Code:
/*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
 
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.
 
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.

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.

Code:
printf("Hi! I am process #%d\n",pid_t);

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.
 
That last line should be:
Code:
printf("Hi! I am process #%d\n",[color=red][b]my_pid[/b][/color]);
 
Thanks alot, got it to work. Can't believe I didn't notice that. Thanks once again for the help
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.