PDA

View Full Version : C Programming - Beginner's Help




NeoPharoah
Oct 1, 2009, 05:16 PM
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



pilotError
Oct 1, 2009, 05:51 PM
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.

electroshock
Oct 1, 2009, 05:57 PM
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.

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.

kainjow
Oct 1, 2009, 05:57 PM
That last line should be:
printf("Hi! I am process #%d\n",my_pid);

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