Solved

Running a c file in linux enviroment

Posted on 2011-09-25
9
240 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

930 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

12 Experts available now in Live!

Get 1:1 Help Now