LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   c programming hello world in linux? how? (https://www.linuxquestions.org/questions/linux-newbie-8/c-programming-hello-world-in-linux-how-289569/)

keiwu 02-13-2005 04:09 AM

c programming hello world in linux? how?
 
I want to compile a "hello world" program written in C, the output I expeced was the text "hello world". I got no idea how to do it. I saw some others do it in school's computer, they run it in a place like dos and type some command line and the text "hello world" is displayed. I want to know what should I do if I am using fedora 3, and how can I get to that "dos" mode to do it? So new to linux, any helps are apprecated.

__J 02-13-2005 04:15 AM

a console/xterm/konsole/gnome-terminal (basically, whatever command line you have, should be in your menu's somewhere) is your command line. open up a editor, put something like this in:

#include <stdio.h>

int main(int argc, char* argv[])
{
printf("hello world\n");
return 0;
}

and save the file to something like hello.c. then, in your command line, do (this is assuming you have a c compiler on your machine):

gcc hello.c -o hello

then to run the program:

./hello

pradeepmenon777 02-13-2005 08:45 AM

i recommend you to buy some book on linux programming ,
so that you can slove all your problems on your own from now on. as you will face delay in replies in here

even i use to do this , refering books rather than doubt clearing every now and then in forums.

enjoy- this book is relly good - Linux programming bible by John Goerzen

keiwu 02-13-2005 12:24 PM

thank you
I still need some basic knowledge before I can do other things

keiwu 02-13-2005 12:45 PM

Quote:

Originally posted by __J
a console/xterm/konsole/gnome-terminal (basically, whatever command line you have, should be in your menu's somewhere) is your command line. open up a editor, put something like this in:

#include <stdio.h>

int main(int argc, char* argv[])
{
printf("hello world\n");
return 0;
}

and save the file to something like hello.c. then, in your command line, do (this is assuming you have a c compiler on your machine):

gcc hello.c -o hello

then to run the program:

./hello

thank you!!
what If I want to compile C++, what should I do? type in the command lines?

harken 02-13-2005 12:55 PM

To compile C++ code you can use g++ instead of gcc with the same syntax: 'g++ hello.cpp -o hello'. But you don't need to do that until you don't write actual C++ code. If you want to see a list of C++ specific functions take a look here .

keiwu 02-13-2005 01:00 PM

wow!! fast response. I've learned lots of things since yesterday!! Great forum!!

mebrelith 02-13-2005 01:15 PM

Get your hands on a book such as "SAMS Teach yourself C++ for Linux in 21 days", is very helpful for a total noob.

pradeepmenon777 02-13-2005 02:13 PM

that is what i exactly wanted to say now!!
i thought that you had some concepts of linux

i take back my words
i would recommend the same as above


All times are GMT -5. The time now is 11:23 PM.