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

Dragonlance1561

macrumors member
Original poster
Aug 16, 2007
68
6
ok I know this sounds dumb but it really isn't working right!

this is my code:
#include <stdio.h>

int main()
{
printf("Hello World/n");
return 0;
}

I saved that as a .c file to my home directory

next I opened terminal.app, and this what I did and the problem that followed: (Soroshi is the name of my home directory)

Last login: Sat Dec 6 00:11:07 on ttys000
macbook-pro:~ Soroshi$ gcc hello.c -o hello.app
macbook-pro:~ Soroshi$ ./hello.app
Hello World/nmacbook-pro:~ Soroshi$

My issue is that the /n shouldn't have appered and the "macbook-pro:~ Soroshi$" should have appeared on the next line.

btw I'm using the gcc compiler that came with Xcode which I downloaded from the apple ADC website.

hope that all makes sense!
 

Dragonlance1561

macrumors member
Original poster
Aug 16, 2007
68
6
omg I can't believe i didn't see that! I feal really dumb now...
oh well... everyone makes mistakes thats how we learn!

another question though. how do I compile from a folder such as /home/documents/C programs instead of having to put it in my home directory to compile them because that could get annoying.
 

Padraic

macrumors regular
you should just be able to drop to a terminal, change to your working directory and compile...

If for some reason that doesn't work try this from your /home/documents/C programs directory

Code:
gcc ./hello.c -o hello.app
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
You don't need the .app extension when compiling a simple C program.

Not only don't you need it, but it is very misleading. A .app is an application package that is basically a directory with a lot of support files as well as the executable that is run when you "launch" a package. Traditionally in UNIX executables have NO extension, and are set to executable, so it is easy to tell these files in a directory listing from other types.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.