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

ParishYoung

macrumors 6502a
Original poster
Mar 18, 2008
644
5
Bristol, South West UK
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

macrumors 6502
Jun 1, 2006
334
0
You have to EXECUTE the program. Compiling only builds a binary that you are able to execute.
 

TEG

macrumors 604
Jan 21, 2002
6,621
169
Langley, Washington
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
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.