Solved

Running a c file in linux enviroment

Posted on 2011-09-25
9
244 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

622 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