Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What to do after opening vim name.c and writing the source code? I mean, to compile and execute.

share|improve this question

closed as off-topic by peterph, Jeff Schaller, PersianGulf, G-Man, vonbrand Dec 24 '15 at 16:04

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

3  
rather trivial, simple search for "how to compile a program on Linux" with an internet search service gives plenty of results, – peterph Dec 24 '15 at 15:38
    
But those are all in GUI. Not command line. – Fahim Ferdous Dec 24 '15 at 15:40
    
Search again, resources are plentiful. It took me 5 seconds to find: luv.asn.au/overheads/compile.html. You probably also want to read some introductory tutorial to using UNIX command line, if "that is in GUI" is an issue. – peterph Dec 24 '15 at 15:42
    
you can search like c programming on linux command line – edward torvalds Dec 24 '15 at 15:46

Open or make a new file by:

vim name.c

then write the C program you intend then save and exit by pressing Esc then :wq.
Then compile it as:

gcc name.c -o name

then run it as:

./name

More

share|improve this answer
    
Where do these files go? I mean the save directory. – Fahim Ferdous Dec 24 '15 at 15:16
    
@FahimFerdous by default your terminal starts in your home directory /home/username – edward torvalds Dec 24 '15 at 15:18
    
I believe that you should remove the occurrences of .o from your answer. – G-Man Dec 24 '15 at 15:31
    
The .o extension is for object files, which are compiled but not linked (gcc -C, I believe). Your command compiles and links, so just use -o name – Kevin Dec 24 '15 at 15:33
1  
@FahimFerdous you dont need command links, open your terminal and type man gcc for details on gcc, man vim for vim etc. also you should probably learn basics of bash shell and commands like cd, ls, pwd, nano and mkdir etc – edward torvalds Dec 24 '15 at 15:39

An alternative (after creating name.c) is to type

make name

This will automatically invoke the gcc command shown in edward’s answer (or maybe some variant on it, such as gcc -o name name.c or possibly cc name.c -o name).  This has the trivial advantage of being about ten or twelve fewer characters to type.  It has the more substantial advantage that, if you develop a serious program with multiple source files, you can write a Makefile that describes the relationships and interdependencies among those files, and you will still be able to compile the program by typing make name, even if that needs to invoke many compile commands.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.