[NTLUG:Discuss] Extremely simple C program...

Vaidya, Harshal (Cognizant) HarshalV at pun.COGNIZANT.COM
Sun Aug 11 23:23:23 CDT 2002


try this...

compile it simply by using gcc hello.c
and then run ./a.out

This will run.

#include <stdio.h>

void main()
{
	printf("Hello world!");
	return;
}


Harshal.


-----Original Message-----
From: Wayne Dahl [mailto:w.dahl4 at verizon.net]
Sent: Sunday, August 11, 2002 9:50 AM
To: NTLUG Discussions
Subject: [NTLUG:Discuss] Extremely simple C program...


Lessee...how many irons can I get in the fire?

Ok...I'm attempting to learn C for the very first time (I'm no
programmer and I can hear the laughter now) from a book.  Here's the
first simple program it gives...

/* Example 1.1 Your Very First C Program - Displaying Hello World */

#include <stdio.h>

void main()
{
	printf("Hello world!");
}

So far, so good.  After writing that in gedit and saving it as hello.c,
I issue gcc -c hello.c and get these messages...

hello.c: In function `main'
hello.c:6: warning: return type of `main' is not `int'


Then, when I attempt to link the two by using gcc hello.c hello.o, I get
these messages...


hello.c: In function `main'
hello.c:6: warning: return type of `main' is not `int'
hello.o: In function `main'
hello.o(.text+0x0): multiple definition of `main'
/tmp/ccBEHACq.o(.text+0x0): first defined here
collect2: ld returned 1 exit status

It does not create an a.out file.  It doesn't seem to do anything at all
but return the error messages.  This is an extremely simple
program...and I can't get it to work.  :Þ  At this rate, I'll never
learn C or anything else!  Unfortuately, the book I'm using (Ivor
Horton's Beginning C Programming) doesn't account for a possible problem
with the compiler. I don't see anything wrong with what I'm doing
(obviously, or I wouldn't be asking for your input), but there's surely
something wrong here.  Any help would be appreciated.

Thanks, 
Wayne


_______________________________________________
http://www.ntlug.org/mailman/listinfo/discuss


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: InterScan_SafeStamp.txt
Url: http://ntlug.org/pipermail/discuss/attachments/20020812/40d95595/InterScan_SafeStamp.txt
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: InterScan_Disclaimer.txt
Url: http://ntlug.org/pipermail/discuss/attachments/20020812/40d95595/InterScan_Disclaimer.txt


More information about the Discuss mailing list