Compiling the program
Let the name of our program is CPROG.C. To enter and compile the C program, follow these steps:
- Make the active directory of your C programs and start your editor. For this any text editor can be used, but most C compilers such as Borland's Turbo C++ has an integrated development environment (IDE) that lets you enter, compile, and link your programs in one convenient setting.
- Write and save the source code. You should name the file CPROG.C.
- Compile and link CPROG.C. Execute the appropriate command specified by your compiler's manuals. You should get a message stating that there were no errors or warnings.
- Check the compiler messages. If you receive no errors or warnings, everything should be okay. If there is any error in typing the program, the compiler will catch it and display an error message. Correct the error, displayed in the error message.
- Your first C program should now be compiled and ready to run. If you display a directory listing of all files named CPROG you will get the four files with different extension described as follows:
- CPROG.C, the source code file
- CPROG.BAK, the backup file of source file you created with editor
- CPROG.OBJ, contains the object code for CPROG.C
- CPROG.EXE, the executable program created when you compiled and linked CPROG.C
- To execute, or run, CPROG.EXE, simply enter cprog. The message, This is a C program is displayed on-screen.
Now let us examine the following program:
/* First Program to learn C */ // 1
#include <stdio.h> // 3
main() // 5
printf("This is a C program\n"); // 7
return 0; // 9
} // 10
|Sample Chapters from book DATA RECOVERY WITH AND WITHOUT PROGRAMMING by Author Tarun Tyagi
Publishers of the Book
Number of Pages
Price of the Book
BPB Publications, New Delhi, India
$69.00 (Including Shipping Charges, Cost of Book and Other expenses, Free Source Code CD included with the Book)