how to write a c program in terminal

Asked by mayank

i want to write a c program in terminal but I don't know how to compile after using g edit.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#1

Please tell which editor are you using...?

Thank you

Revision history for this message
himanshupratap (himanshupratap) said :
#2

you can write down c program in vi editor. you need to know the short cut keys to work upon vim editor .
the details are at following site .
http://www.cyberciti.biz/faq/compiling-c-program-and-creating-executable-file/

however if you wish to use gedit (which is comparitively much easier and simpler to use )
 the steps to write and compile c program is as follows :

i am using the gcc compiler for c and g++ compiler for c++.
both gcc and g++ comes along with ubuntu os , so they must pre installed in your system (if you are using ubuntu).

1. to write a c program , use the gedit editor and save the program with program_name.c at your desired location.

2. open the terminal window and change the directory to one where your source program is being save .
say for example if your myprog.c is located in folder Documents , you can make use of this command " cd ".
$cd Documents
/Documents$

3. to compile the progrma use the command syntax
gcc -Wall <program_name.c> -o <output_filename >

note-
-Wall is being used to display all warnings
-o denotes that next written filename is the ouput executable fiel name to be generated on successful copilation.

example:
/Documents$ gcc -Wall myprog.c -o myprog

4.to run the program , your program must be successfully compiled , follow the syntax
/Documents$ ./<output_filename>

example:

/Documents$ ./myprog

Revision history for this message
sumeesh n s (mysumeesh) said :
#3

its working. thank u

Can you help with this problem?

Provide an answer of your own, or ask mayank for more information if necessary.

To post a message you must log in.