C under LINUX (Using Sublime-Text and Terminal)
This post is about to how we can write, compile and run a C program in LINUX OS. (I use Ubuntu 14.10)
To compile a program we need a compiler. There is a pre-installed compiler in Ubuntu named GCC (GNU C Compiler). In case you don't have this, don't worry you can install it easily by using the following steps.
Installing GCC in Ubuntu -
1. Open Terminal. (press key alt+ctrl+T)
2. Write the following code
'$ sudo apt-get update' and hit Enter key
It will ask for password of administrator, enter it and press Enter key
It takes some time to update cache list and finally done.
3. Now to download GCC write the following command
'$ sudo apt-get install gcc'
(maybe it ask for password again)
And it downloads and installs latest version of GCC.
Now we are ready with our compiler.
Setting up Sublime Text-
The next we need that is a text editor. There is a text editor pre-installed named 'gedit', but if we don't want to use this, we have some another text editors in which I found 'Sublime text' most helpful.
You can from download sublime text or go to website http://www.sublimetext.com/ for latest version. Downloaded file is a *.deb file which you can install directly by double clicking it.
Now we open Sublime Text and start coding.
Write some code -
<1> first open a new window (by key ctrl+N)
<2> choose syntax of your code, press ctrl+shift+p key to open a search box, search for 'set syntax:c' select it.
<3> now sublime itself help you to write correct syntax.
<4> Write your code in the window like my sample code.
#include <stdio.h>
int main(int argc, char const *argv[])
{
printf("Hello World! \n");
return 0;
}
we are ready with our code to cpmpile.
<4> save the file where you want using *.c as I save 'sample.c'
<5> open trmianal (alt+ctrl+T)
<6> change directory to your code file (by default terminal opens '/home/user' directory) by '$cd directory name' , in my case that is '$cd Projects/C' where I saved the file.
<7> now write command '$gcc -Wall -o sample sample.c' to compile your code (if there will be any error it will shown down and if not then program compiled successfully)
<8> now run your program by '$ ./sample' after that it will shows the result of program.
NOTE -
(i) Every time you edit the source file (sample.c) , you have to save it before compile it and then run.
(ii) don't use 'clrscr()' , 'getch()' ,'void main()', and '<conio.h>' in program. GCC doesn't supports these functions.
So this is it!
For any query, write in comment box..




My response on my own website. Appreciation is a wonderful thing...thanks for sharing keep it up. Wondershare Filmora Crack
ReplyDeleteAiseesoft Total Video Converter Crack
Passport Photo Maker Crack
Sublime Text Crack
Sandboxie Crack