LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2006, 06:15 PM   #1
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Rep: Reputation: 45
hello.c - now what?


I am just trying to print a simple "Hello, world!" but it won't work. Here is the content of hello.c
Code:
main()
{
	printf("hello, world\n");
}
I then type cc hello.c and I get some errors. Isn't cc a C compiler?

Also, if I add the \a, is the computer supposed to beep?
Code:
main()
{
	printf("hello, world\n");
        printf("\a");
}

Last edited by Micro420; 11-22-2006 at 06:28 PM.
 
Old 11-22-2006, 07:02 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
#include <stdio.h>

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

	printf("hello, world\n");
	printf("\a");
	return 0;
}
if the file is saved as hello_world.c
Quote:
gcc hello_world.c
man gcc for options.
 
Old 11-22-2006, 07:02 PM   #3
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 387

Rep: Reputation: 33
Try:

Code:
#include <stdio.h>

main()
{
        printf("hello, world\n");
        printf("\a");
}
That should get rid of the warning. Then cc hello.c -o hello
This should make a binary called hello.

Without the "-o" flag it will only make assembler output (a.out) and no binary. You can run a.out like any other binary. I never bothered trying that.



vxc

Last edited by vxc69; 11-22-2006 at 07:07 PM.
 
Old 11-23-2006, 03:38 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you can use

make hello
Code:
billym.primadtpdev>make hello   
gcc     hello.c   -o hello
to do the in-built make rules.

(no you don't need a makefile)
 
Old 11-25-2006, 09:20 PM   #5
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Original Poster
Rep: Reputation: 45
Great! Adding the #include <stdio.h> did the trick! I can print Hello, world now!

Last edited by Micro420; 11-25-2006 at 09:25 PM.
 
Old 11-26-2006, 12:26 AM   #6
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Rep: Reputation: 15
Even if you don't add #include <stdio.h> you receive at most a warning like this one:
Code:
implicit declaration of printf
but the code still gets compiled.

Last edited by BiThian; 11-26-2006 at 12:28 AM.
 
Old 11-26-2006, 12:43 PM   #7
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by BiThian
Even if you don't add #include <stdio.h> you receive at most a warning like this one:
Code:
implicit declaration of printf
but the code still gets compiled.
Thanks! I edited my post so others may not know what you are talking about. I was getting that warning error, but I later installed some build tools on my Ubuntu Linux and that warning message went away. But you are correct in that the binary was still able to build after the warning message. Now it's time to learn more about C! I've ordered tons of books on C and am eager to learn this language.
 
Old 11-26-2006, 12:55 PM   #8
BiThian
Member
 
Registered: Aug 2006
Location: Romania
Distribution: NetBSD 3.1
Posts: 118

Rep: Reputation: 15
I think these two books are enough
Kernighan & Ritchie - C Programming Language
Stephen Prata - C Primer Plus (5th Edition) ( a ***** book )

Last edited by BiThian; 11-26-2006 at 12:56 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration