PDA

View Full Version : Complete Noob Question - learning C Hello World problems




ParishYoung
Mar 18, 2008, 04:03 PM
Hi All,

I am completely new to programming and am currently learning C using X-Code and an ebook I downloaded from Spiderworks.com

It's a real beginner course and I am stumbling at the first block.

I have downloaded the Xcode program which opens and runs fine.

However when using the simple example programs which are designed to simply display text on the screen.

When I press build and go i get another window showing that "build was successful" but there is no output of the relevant text.

Here is the code (remember it's only C):

#include <stdio.h>

void SayHello( void );

int main (int argc, const char * argv[])
{
SayHello();
SayHello();
SayHello();

return 0;
}


void SayHello( void )
{
printf( "Hello, world!\n" );
}


Please can someone tell me where I'm going wrong?

Many thanks in advance.

Parish



antibact1
Mar 18, 2008, 04:09 PM
You have to EXECUTE the program. Compiling only builds a binary that you are able to execute.

TEG
Mar 18, 2008, 04:12 PM
printf need a format qualifier after your string so you need

printf("Hello World!\n", %s);

then just gcc file.c

then ./a.out

TEG

ParishYoung
Mar 18, 2008, 04:13 PM
Doesn't the "Build and Go" button compile it and then run it??

ParishYoung
Mar 18, 2008, 04:14 PM
@TEG

I literally started the ebook this morning so what you say is still double dutch to me.

What is GCC??

Cromulent
Mar 18, 2008, 04:21 PM
printf need a format qualifier after your string so you need

printf("Hello World!\n", %s);

No it doesn't.

printf("Hello World!\n"); is perfectly valid code. Your version is not, format qualifiers are used when you want to insert a variable in the string that printf prints. Not to specify what the string actually is.

martintyler
Mar 18, 2008, 04:21 PM
printf need a format qualifier after your string so you need

printf("Hello World!\n", %s);



??? The original printf is fine. Yours wont even compile.

Cromulent
Mar 18, 2008, 04:23 PM
Please can someone tell me where I'm going wrong?

Many thanks in advance.

Parish

Go to the run menu and click on Console. Then click build and go and you will see your output in the console window.

ParishYoung
Mar 18, 2008, 04:31 PM
@Cromulent

Thanks man. When I did that it showed all of the 50 thousand times i'd presses Build and Go.

Thanks to all for they help here. Lets see how I get on.