The steps involved in developing a C program are :
1. Program creation
2. Program compilation
3. Program execution
Unix/Linux Environment
(a) Program creation
In UNIX environment, file can be created with vi editor as :$vi filename.c
Here $ is the unix prompt. Type "i", it enables you to write your code. The file can be saved by pressing ESC and SHIFT+zz.
(b) Program compilation
After creation of C program, it can be compiled as :$gcc filename.c
If the program has mathematical function then it is compiled as :$gcc filename.c -lm
After compilation, the executable code is stored in the file a.out.
Another way of compilation providing executable file name is :$gcc filename.c -o executablename
After compilation, the executable code is stored in the file executablename.
(c) Program execution
After the compilation of program, it can be executed as :$ a.out
If compiled with -o option then it can be executed as :$ executablename
If GCC (GNU Compiler Collection) is not installed, then you will have to install it yourself using the detailed instructions available at https://gcc.gnu.org/install/
MS-DOS Environment (Command Line)
(a) Program creation
The program file can be created using any editor and should be saved with .c extension
(b) Program compilation
After saving the file, C program can be compiled at DOS prompt by writing :C:\>tcc filename (in Turbo C)
C:\>bcc filename (in Borland C)
(c) Program execution
After compilation of C program, the executable file filename.exe is created. It is executed at DOS prompt by writing :C:\> filename
Using an IDE - Turbo C
(a) Program creation
Step 1 :
Open turbo C IDE(Integrated Development Environment), click on File and then click on New
Step 2 :
Write the code as shown below:
/* my first program in c */
#include <stdio.h>
int main()
{
printf("Hello, World !");
return 0;
}
(b) Program compilation
Step 3:
Click on compile or press Alt+F9 to compile the code
(c) Program execution
Step 4:
Click on Run or press Ctrl+F9 to run the code
Step 5:
The output appears in the output window that can be seen using the keys Alt+F5
Using an IDE - Visual Studio 2013
(a) Program creation
Step 1 :
Create a new general empty project in Visual C++.
To create an empty project
- On the FILE menu, Click New Project or press Ctrl + Shift + N.
- In the left pane under Installed | Templates chose Visual C++ and select General.
- In the middle pane, select Empty Project.
- Set the Name and Location values for your solution, then click OK.
Step 2 :
Add a new .cpp file Source.cpp.
To add a new source file
- In Solution Explorer, right-click the Source Files folder, point to Add, and then click New Item or press Ctrl + Shift + A.
- In the Code node, click C++ File (.cpp), type a name for the file, and then click Add.
Step 3:
Write the code as shown below:
/* my first program in c */
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Hello World !");
_getch();
return 0;
}
On the DEBUG menu, click Start without Debugging or press Ctrl + F5.
Step 6:
Review the resulting program window
No comments:
Post a Comment