PDA

View Full Version : Very sadly having problems with the hello world program in C.




Dragonlance1561
Dec 6, 2008, 02:45 AM
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!



SydneyDev
Dec 6, 2008, 02:51 AM
Try \n instead of /n

Dragonlance1561
Dec 6, 2008, 03:23 AM
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
Dec 6, 2008, 05:00 AM
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

gcc ./hello.c -o hello.app

Cromulent
Dec 6, 2008, 05:37 AM
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

gcc ./hello.c -o hello.app

You don't need the .app extension when compiling a simple C program.

lee1210
Dec 6, 2008, 11:20 AM
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