header files-
Include statements call include files (sometimes also referred to as "header files") which are text files containing
information about function declarations, constants and structures. When your program is compiled, the
information in the specified include file is 'pasted' directly into your program.
/* Examples: */
| #include | math.h
| incl. file with math. function info |
| #include | stdio.h
| include file with I/O info |
| #include | time.h | include file with time funct. info |
| #include | graph.h
| include file with graphics info |
| #include | myconst.h
| see example directly below |
Function Declarations -
There are two different categories of functions that you will use in your C programs: predefined
functions and functions that you will write.
Predefined functions were written by someone else and are stored in some function library on your
hard disk, ready to be used by anyone who so desires. During the course we will provide you with
predefined functions to simplify the programming needed in the lab.
These functions consist of a core of standard ANSI C functions that cover most basic programming tasks
such as input and output, file maintenance and the basic mathematical functions.
Do not panic when you look over the list of functions; of the hundred or
so functions, you really need to know only about 10 functions but you should be aware that some of the
other ones exist. Here is a table of functions that you should know:
Function Include
| Name | File Description | Usage |
| printf( ) | stdio.h | Prints formatted data to screen Display numbers and text |
| scanf( ) | stdio.h
| Reads in formatted data. To read in numbers |
| puts( ) | stdio.h | Prints character string to screen Display text |
| gets( ) | stdio.h | Reads in a string (termin. by carriage return) To read in text |
| kbhit( ) | conio.h
| Detects if any key on keyboard has been hit To stop a repeated process |
| inp( ) | conio.h | Reads a byte of data from a port Computer interfacing |
| outp( ) | conio.h
| Sends a byte of data to a port Computer interfacing |
| malloc( ) | stdlib.h | Creates a data buffer Arrays and data input |
| rand( ) | stdlib.h | Creates a random # between 0 and 32768 Simulations, Tests |
| pow( ) | math.h | Calculates x |
| sqrt( ) | math.h | Calculates x |
Global Variables -
Any variables declared outside of 'main' will be global, i.e. they can be "seen" by 'main' and any other
functions.
If you don't understand what local and global variables are, don't worry; they are explained in more.
main( ) -
Every C program needs a 'main' function. This is the place where the main body of your code is
placed. A successful C program executes all the statements placed in main. Functions are only executed
if they are called from within 'main'. Main is the only C function that doesn't need to be declared.
Now lets start some programing -
#include
#include
void main( )
{
printf("is innovation is better then dreaming");
}
getch();
}
if you are using turbo c++ compiler then
for compiling use alt+F9
for running the program use ctrl+F9
let see whats the output-
is innovation is better then dreaming
thats all folks..please make it revise it all the things that i delivered today..from tommorow onward we will go for real programing.
No comments:
Post a Comment