Search This Blog

Friday, May 25, 2012

Program Library


Program Library


In programming a collection of pre-compiled routines that a program can use is known as a Program Library.
These routines are stored in object format. They are known as library functions or routines. Libraries are especially useful for storing frequently used routines because you do not have to explicitly link them to every program that uses them. The linker automatically looks in libraries for routines that it does not find elsewhere.


Runtime Library


Runtime refers to the event that a program is being executed. The library routines (functions) that are bound to the program during execution are known as runtime library. A linker links the object code of a program to the runtime library in order to produce an executable code of a program.


Linker


Many programming languages allow you to write different pieces of code called modules separately. This
technique simplifies the programming task because you can break a large program into small more manageable tasks; also called divide and conquer. However, finally you need to put all these modules together. This is done by a program known as a linker.

A linker is also called a link editor (binder). So a linker combines all object modules into one executable
program.

A linker also does another job. It replaces the symbolic addresses you use with real addresses. Therefore
even if your program contains one module it has to be linked.

Saturday, May 12, 2012

Reading a character


Reading a character


getc()

getc() is a macro that reads one character from a stream.

getchar()
getchar() is a macro that gets a character from stdin. It returns the next character on the input stream stdin.

Eg:-1
/* Reading a character from the keyboard */
#include <stdio.h>
void main()
{
char ch;
printf("Enter a character:");
ch = getc(stdin);
printf("You have entered the character %c\n",ch);
}

Friday, May 11, 2012

Header files



Header files



C/C++ has a number of header files that hold the information it needs to know about the library functions. They provide function prototype declarations for library functions. Data types and symbolic constants used with the library functions are also defined in them; along with global variables defined by the library functions. Header files are required by the include directives because include directives are always placed at the head of a C program. The < > (angle bracket) around a header file tells the C preprocessor to look for the header file in a directory other than the “code”.



Frequently used Header Files


Some of the frequently used header files, and library functions they contain are listed below.
<stdio.h>        Defines the standard I/O predefined streams, stdin, stdout, stdprn and stderr and declares
                      stream-level I/O routines.
<stdlib.h>       Declares several commonly used routines: conversion routines, search/sort routines and other
                       miscellany.
<string.h>       Declares several string and memory manipulation routines.
<search.h>     Declares functions for searching and sorting.
<memory.h>   Declares memory manipulation functions
<mem.h>        Declares memory manipulation functions
<math.h>        Declares prototypes for the math functions
<malloc.h>     Declares memory management functions and variables.
<io.h>            Contains structures and declarations for low level input/output routines.
<graphics.h>   Declares prototypes for graphics functions
<float.h>          Contains parameters for floating point routines.
<errno.h>         Defines constant mnemonics for the error codes.
<dos.h>           Defines various constants and gives declarations needed for DOS and 8086 specific calls.
<dir.h>             Contains structures, macros and functions for working with directories and path names.
<ctype.h>         Contains information used by the character classification and character conversion macros.
<conio.h>         Declares various functions used in calling the DOS console I/O routines.
<complex.h>    Declares the C++ complex math functions.
<bios.h>           Declares various functions used in calling IBM-PC ROM BIOS routines.
<alloc.h>         Declares memory management functions. (allocation, deallocation etc.)
<time.h>          Defines a structure filled in by the time conversion routines and a type used by other time
                      routines also provides prototypes for these routines.

Friday, May 4, 2012

Standard Input


3.

/* Employee Data */
#include <stdio.h>
#include <conio.h>
void main()
{ int empnum;
char name[10];
int dd, mm , yyyy;
float salary;
clrscr();
printf("Enter employee number:");
scanf("%d",&empnum);
printf("Enter name :");
scanf("%10s", &name);
printf("Enter date dd/mm/yyyy :");
scanf("%2d %2d %4d", &dd, &mm, &yyyy);
printf("Enter salary :");
scanf("%f",&salary);
printf("\n");`
printf("Emp Num :%d \n", empnum);
printf("Name :%s\n", name);
printf("Date of employment :%d%c%d%c%d\n", dd,'/',mm,'/', yyyy);
printf("Salary :%7.2f\n",salary);
}