Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,429 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,901 people online right now. Registration is fast and FREE... Join Now!




c under linux

2 Pages V  1 2 >  
Reply to this topicStart new topic

c under linux

cricketfancy
12 Jan, 2008 - 10:17 PM
Post #1

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 15


My Contributions
how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.

User is offlineProfile CardPM
+Quote Post

jjhaag
RE: C Under Linux
12 Jan, 2008 - 10:30 PM
Post #2

me editor am smartastic
Group Icon

Joined: 18 Sep, 2007
Posts: 1,789



Thanked: 2 times
Dream Kudos: 775
Expert In: C,C++

My Contributions
Moved to C/C++.

Please read the rules and post in the correct forum.

And welcome to </dic> smile.gif
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: C Under Linux
13 Jan, 2008 - 02:05 AM
Post #3

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(cricketfancy @ 12 Jan, 2008 - 11:17 PM) *

how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.



You could use a text editor to write the code, then save the file as a e.g. nameOfTheFile.c

Then you can use the command line to compile the code, you should be in the folder where the .c file is.

So write:

gcc nameOfTheFile.c

and if there are no errors to run your program do:

a.out

or

./a.out
User is offlineProfile CardPM
+Quote Post

cricketfancy
RE: C Under Linux
13 Jan, 2008 - 04:25 AM
Post #4

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 15


My Contributions
QUOTE(PennyBoki @ 13 Jan, 2008 - 03:05 AM) *

QUOTE(cricketfancy @ 12 Jan, 2008 - 11:17 PM) *

how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.



You could use a text editor to write the code, then save the file as a e.g. nameOfTheFile.c

Then you can use the command line to compile the code, you should be in the folder where the .c file is.

So write:

gcc nameOfTheFile.c

and if there are no errors to run your program do:

a.out

or

./a.out

it is giving an error as follows:
bash: a.out: command not found
also tried ./a.out but:
bash: ./a.out: No such file or directory
also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............

User is offlineProfile CardPM
+Quote Post

revenge2
RE: C Under Linux
13 Jan, 2008 - 05:05 AM
Post #5

New D.I.C Head
*

Joined: 25 Dec, 2007
Posts: 25


My Contributions
hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: C Under Linux
13 Jan, 2008 - 05:52 AM
Post #6

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(cricketfancy @ 13 Jan, 2008 - 05:25 AM) *

also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............


ok for the run try this:

./nameOfTheFile.c

and the headers include them in the .c file.
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: C Under Linux
13 Jan, 2008 - 06:04 AM
Post #7

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(revenge2 @ 13 Jan, 2008 - 06:05 AM) *

hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing


For ubuntu try:

$ gcc nameOfTheFile.c

then:

$ ./a.out

Now, I want to show you a trick it's called google wink2.gif

go to www.google.com

just write the question you need and there and there you go.

smile.gif Hope this helps.

This post has been edited by PennyBoki: 13 Jan, 2008 - 06:05 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: C Under Linux
13 Jan, 2008 - 06:13 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
As for the question about conio.h, graphics.h, etc...it will depend on the library. You cannot include conio.h on linux, as it is platform dependant. You'll habe to check whatever library you want to include to see if it's available for your platform.

The standard C library is as follows:

http://www.utas.edu.au/infosys/info/docume.../C/CStdLib.html

User is offlineProfile CardPM
+Quote Post

cricketfancy
RE: C Under Linux
13 Jan, 2008 - 08:59 AM
Post #9

New D.I.C Head
*

Joined: 12 Jan, 2008
Posts: 15


My Contributions
QUOTE(PennyBoki @ 13 Jan, 2008 - 06:52 AM) *

QUOTE(cricketfancy @ 13 Jan, 2008 - 05:25 AM) *

also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............


ok for the run try this:

./nameOfTheFile.c

and the headers include them in the .c file.

hi,
thanks for giving responses.............
but the issue still remains
firstly after tryingg to run by ./nameofthefile.c error came as:
bash: ./sample.c: Permission denied
next
compiler gave error messages for clrscr() and getch() functions
sample.c:(.text+0xa): undefined reference to `clrscr'
sample.c:(.text+0x23): undefined reference to `getch'
lastly
does the ./ concept work under fedora...........
under ubuntu it did work..............
but what about fedora?
coz its giving errors all the time!!


User is offlineProfile CardPM
+Quote Post

Tom9729
RE: C Under Linux
13 Jan, 2008 - 09:57 AM
Post #10

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,463



Thanked: 10 times
Dream Kudos: 325
My Contributions
cc -o name_of_executable name_of_source.c will compile your source.
./name_of_executable will run the executable.

If you get errors compiling, the executable will not be made.

Also, you can't execute the source code. That only works with interpreted languages like Perl and Bash.

Can you please post the code you're trying to compile? I don't think clscr is a standard function...

It's also worth noting that there are plenty of C IDE's out there. I don't understand why people think that programming on Linux always means calling GCC from the commmand line...

Try Eclipse CDT, Anjuta, KDevelop.

All of them should be available from your distribution's package manager.
User is offlineProfile CardPM
+Quote Post

MorphiusFaydal
RE: C Under Linux
13 Jan, 2008 - 03:48 PM
Post #11

D.I.C Lover
Group Icon

Joined: 12 May, 2005
Posts: 1,113



Thanked: 9 times
Expert In: Hardware, Networking

My Contributions
clrscr() and getch() are both functions in conio.h which is Windows only. I had that problem the first time I tried to build a program in Linux.
User is offlineProfile CardPM
+Quote Post

Bench
RE: C Under Linux
13 Jan, 2008 - 03:53 PM
Post #12

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 630



Thanked: 16 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
QUOTE(revenge2 @ 13 Jan, 2008 - 01:05 PM) *

hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing

I installed Ubuntu a while back, and I noticed that it does not come with all the files which you need in order to compile and run C code.

Have a look at this thread which details how to install the files you need

http://ubuntuforums.org/showthread.php?t=120421
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/5/08 04:55AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month