Solved

Running a c file in linux enviroment

Posted on 2011-09-25
9
238 Views
Last Modified: 2012-06-21
Hello Experts..

I am a newbie to linux and need to know how I can compile and run this c program.

I don't have any enviroments setup on my computer.  So I am looking to get a "how to" so I can run this file.

Thanks dad.c
0
Comment
Question by:Maliki Hassani
9 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 36595970
You will need to download gcc if it's not installed.
gcc dad.c -o dad
./dad

Open in new window

That will compile dad.c into an executable named dad, then run it.
0
 

Author Comment

by:Maliki Hassani
ID: 36596004
okay, I am doing it now..  Can you talk me through how I would run the file?  
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36596007
If you typed command 1 exactly as I pasted it, then command 2 will execute it.
0
 
LVL 21

Expert Comment

by:Papertrip
ID: 36596008
Ah I can see how my wording on the initial reply could have been confusing.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36596973
In Linux, the following should work.  (Assumes your source file is called foo.c)

$ make foo
$ ./foo


make foo will run the compiler and linker.
./foo will run the program.

0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36596977
Are you trying to learn C or are you just trying to port the software?

If the program is complicated, or you plan to write complicated programs in the future, I suggest you learn about make.  (If you need pointers, EE is a place to ask).

Also, if you are learning C, I suggest you also try to learn C++.  (This is even more important if you are right brain dominant.)
0
 
LVL 24

Expert Comment

by:fridom
ID: 36597094
No, make will  not work without having  a proper Makefile.
The proper command is by Papertrip.
0
 
LVL 2

Accepted Solution

by:
xeltek earned 250 total points
ID: 36597880
Hi,
I checked your code,  gcc will compile and no other 3rd party library needed.
What linux distro you are using? then we can help to install the compiler.
gcc:
http://gcc.gnu.org/
a brief tutorial:
http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

I tested your code in my ubuntu server box:

root@ubuntu:/srv/ftp# gcc dad.c -o dad
root@ubuntu:/srv/ftp# ./dad


Please choose the assignment to run:

2. Assignment 2
3. Assignment 3
4. Assignment 4
0. Quit

Please enter the number of your choice:

Open in new window


Installation of gcc in ubuntu box will be:
#apt-get install gcc
0
 
LVL 13

Assisted Solution

by:Hugh McCurdy
Hugh McCurdy earned 250 total points
ID: 36598796
fridom, make works for me, out of the box, without having a Makefile.  Of course, I create a Makefile for more complicated compilations.

hmccurdy@dagmar:~/empire/c/hello$ ls -l
total 4
-rw-r--r-- 1 hmccurdy hugh 56 2011-09-25 23:28 hello.c
hmccurdy@dagmar:~/empire/c/hello$ make hello
cc     hello.c   -o hello
hmccurdy@dagmar:~/empire/c/hello$ ./hello
Hello
hmccurdy@dagmar:~/empire/c/hello$ 

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now