Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Running a c file in linux enviroment

Posted on 2011-09-25
9
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
LVL 21

Expert Comment

by:Papertrip
ID: 36596008
Ah I can see how my wording on the initial reply could have been confusing.
0
 
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 1000 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 1000 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

715 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