> August 2011 ~ Online tutorial

ARRAY

Loop statement in c

Directive in c

MATH.H

STDIO.H

ALLOC.H

unixtodos() in c


 unixtodos()

 Converts date and time from UNIX to DOS format

 Declaration:

   void unixtodos(long time, struct date *d, struct time *t);

 Remarks:

unixtodos converts the UNIX-format time given in time to DOS format and
fills in the date and time structures *d and *t.

 Return Value:
None


 Example:

 #include <stdio.h>
 #include <dos.h>

 char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

 #define SECONDS_PER_DAY 86400L  /* the number of seconds in one day */

 struct date dt;
 struct time tm;

 int main(void)
 {
    unsigned long val;

 /* get today's date and time */
    getdate(&dt);
    gettime(&tm);
    printf("today is %d %s %d\n", dt.da_day, month[dt.da_mon], dt.da_year);

 /*convert date and time to unix format (num of seconds since Jan 1, 1970*/
    val = dostounix(&dt, &tm);
 /* subtract 42 days worth of seconds */
    val -= (SECONDS_PER_DAY * 42);

 /* convert back to dos time and date */
    unixtodos(val, &dt, &tm);
    printf("42 days ago it was %d %s %d\n",
           dt.da_day, month[dt.da_mon], dt.da_year);
    return 0;
 }

getverify() in c and setverify() in c

getverify() , setverify()
  • getverify gets the verify state
  • setverify sets the verify state
Declaration:
int getverify(void);
void setverify(int value);
Remarks:
getverify gets the current state of the verify flag.
setverify sets the current state of the verify flag to value.
The verify flag controls output to the disk.When it is off, writes are not verified.When it is on, disk writes are verified to ensure the data is written properly.
Return Value:
getverify returns 0 if the verify flag is off, 1 if the flag is on
setverify does not return

Example :

    #include <stdio.h>
     #include <conio.h>
     #include <dos.h>

     int main(void)
     {
        int verify_flag;

        printf("Enter 0 to set verify flag off\n");
        printf("Enter 1 to set verify flag on\n");

        verify_flag = getch() - 0;

        setverify(verify_flag);

        if (getverify())
           printf("DOS verify flag is on\n");
        else
           printf("DOS verify flag is off\n");

        return 0;
     }

sound() in c

sound(),nosound()
sound turns the PC speaker on at the specified frequency
nosound turns the PC speaker off
Declaration:
void sound(unsigned frequency);
void nosound(void);
Remarks:
sound turns on the PC's speaker at a given frequency.
nosound turns the speaker off after it has been turned on by a call to sound.
frequency specifies the frequency of the sound in hertz (cycles per second).
Return Value:
None
Example :


 #include <dos.h>

 int main(void)
 {
    sound(7);
    delay(10000);
    nosound();
    return 0;
 }




setdate() in c

setdate()
Gets or sets DOS system date
Declaration:
void setdate(struct date *datep);
Remarks:
setdate sets the system date to the date in *datep.
Return Value:
getdate: None
On success, returns 0
Otherwise, returns a non-zero value and
sets errno to EINVAL (Invalid date)

Program



#include <stdio.h>
#include <process.h>
#include <dos.h>

int main(void)
{
   struct date reset;
   struct date save_date;

   getdate(&save_date);
   printf("Original date:\n");
   system("date");

   reset.da_year = 2001;
   reset.da_day = 1;
   reset.da_mon = 1;
   setdate(&reset);

   printf("Date after setting:\n");
   system("date");

   setdate(&save_date);
   printf("Back to original date:\n");
   system("date");

   return 0;
}

getdate() in c

getdate()
Gets or sets DOS system date

Declaration:
void getdate(struct date *datep);
Remarks:
getdate fills in the date structure *datep with the system's current date.
Return Value:
getdate: None
On success, returns 0
Otherwise, returns a non-zero value and
sets errno to EINVAL (Invalid date)
Program
#include <stdio.h>
#include<dos.h>
int main(void)
{
struct date d;
getdate(&d);
printf("The current year is: %d\n", d.da_year);
printf("The current day is: %d\n", d.da_day);
printf("The current month is: %d\n", d.da_mon);
return 0;
}


poke() and pokeb() in c

poke(),pokeb()
poke stores an integer value at the memory location segment:offset
pokeb stores a byte value at the memory location segment:offset
Declaration:
void poke(unsigned segment, unsigned offset, int value);
void pokeb(unsigned segment, unsigned offset, char value);
Remarks:
poke stores the integer value at the memory location segment:offset.
pokeb stores the byte value at the memory location segment:offset.

If you call either of these routines when DOS.H has been included, the routine will be treated as a macro that expands to inline code.
If you don't include DOS.H, or if you do include it and #undef poke (or pokeb), you'll get the function rather than the macro.
Return Value:
None
Example:
#include<stdio.h>
#include <dos.h>
int main(void)
{
clrscr();
cprintf("Make sure the scroll lock key is off and press any key\r\n");
getch();
poke(0x0000,0x0417,16);
cprintf("The scroll lock is now on\r\n");
return 0;
}

keep() in c

keep()
Exits and remains resident
Declaration:
void keep(unsigned char status, unsigned size);
Remarks:
Both _dos_keep and keep use DOS function 0x31 to return to DOS with the exit status in status.
The current program remains resident.
These functions set the program to size paragraphs in length, and free the remainder of the memory of the program.
You can use _dos_keep and keep when installing TSR programs.
Return Value:
None
Program

#include
/* The clock tick interrupt */
#define INTR 0x1C
/* Screen attribute (blue on grey) */
#define ATTR 0x7900

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

/* reduce heaplength and stacklength to make a smaller program in memory */
extern unsigned _heaplen = 1024;
extern unsigned _stklen = 512;

void interrupt ( *oldhandler)(__CPPARGS);

typedef unsigned int (far *s_arrayptr);

void interrupt handler(__CPPARGS)
{
s_arrayptr screen[80];
static int count;

/* For a color screen the video memory is at B800:0000.
For a monochrome system use B000:000 */
screen[0] = (s_arrayptr) MK_FP(0xB800,0);

/* increase the counter and keep it within 0 to 9 */
count++;
count %= 10;

/* put the number on the screen */
screen[0][79] = count + '0' + ATTR;

/* call the old interrupt handler */
oldhandler();
}

int main(void)
{

/* get the address of the current clock
tick interrupt */
oldhandler = _dos_getvect(INTR);

/* install the new interrupt handler */
_dos_setvect(INTR, handler);

/* _psp is the starting address of the
program in memory. The top of the stack
is the end of the program. Using _SS and
_SP together we can get the end of the
stack. You may want to allow a bit of
saftey space to insure that enough room
is being allocated ie:
(_SS + ((_SP + safety space)/16) - _psp)
*/
_dos_keep(0, (_SS + (_SP/16) - _psp));
return 0;
}

/* NOTE:
This is an interrupt service routine.
You can NOT compile this program with Test
Stack Overflow turned on and get an
executable file which will operate
correctly. Due to the nature of this
function the formula used to compute
the number of paragraphs may not
necessarily work in all cases. Use with
care! Terminate Stay Resident (TSR)
programs are complex and no other support
for them is provided. Refer to the
MS-DOS technical documentation
for more information. */

#include
/* The clock tick interrupt */
#define INTR 0x1C
/* Screen attribute (blue on grey) */
#define ATTR 0x7900

#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif

/* reduce heaplength and stacklength to make a smaller program in memory */
extern unsigned _heaplen = 1024;
extern unsigned _stklen = 512;

void interrupt ( *oldhandler)(__CPPARGS);

typedef unsigned int (far *s_arrayptr);

void interrupt handler(__CPPARGS)
{
s_arrayptr screen[80];
static int count;

/* For a color screen the video memory is at B800:0000.
For a monochrome system use B000:000 */
screen[0] = (s_arrayptr) MK_FP(0xB800,0);

/* increase the counter and keep it within 0 to 9 */
count++;
count %= 10;

/* put the number on the screen */
screen[0][79] = count + '0' + ATTR;

/* call the old interrupt handler */
oldhandler();
}

int main(void)
{

/* get the address of the current clock
tick interrupt */
oldhandler = getvect(INTR);

/* install the new interrupt handler */
setvect(INTR, handler);

/* _psp is the starting address of the
program in memory. The top of the stack
is the end of the program. Using _SS and
_SP together we can get the end of the
stack. You may want to allow a bit of
saftey space to insure that enough room
is being allocated ie:
(_SS + ((_SP + safety space)/16) - _psp)
*/
keep(0, (_SS + (_SP/16) - _psp));
return 0;
}

FOR LOOP USING C

**FOR LOOP**
============

#include<studio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1; i<100; i+1)
{
printf("WELCOME");
}
getch();
}

WHILE LOOP PROGRAMMING USING C

**WHILE LOOP PROGRAME**
=======================

#include<studio.h>
#include<conio.h>
void main()
{
int a,b=0,c;
clrscr();
printf("\n a= ");
scanf("%d",&a);
while(a>0)
{
c=a%10;
printf("\n %d%d", c,b);
b=b*10+c;
a=a/10;
printf("%d",a);
getch();
}
printf("%d",b);
getch();
}

REVERSE NUMBER PROGRAMMING USING C

**REVERSE NUMBER PROGRAME**
===========================

#include<studio.h>
#include<conio.h>
void main()
{
int a,b,c,s=0;
clrscr();
printf("\n a= ");
scanf("%d",&a);
while(a>0)
{
a-c=a%10;
printf("%d",c);
s=(s*10)+c;
a=a/10;
}
getch();
}

SET DATE PROGRAMMING USING C

**SET DATE PROGRAME**
=====================

#include<studio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
void main()
{
struct date reset;
reset.da-year=2008;
reset.da-day=17;
reset.da=mon=6;
settime(&reset);
return 0;
}

SET TIME USING C PROGRAM

**SET TIME PROGRAME**
=====================

#include<studio.h>
#include<conio.h>
void main()
{
struct time t;
t.ti-hour=11;
t.ti-min=0;
settime(&t);
}

switch programs using c

**switch programs**
===================

#include<stdio.h>
#include<conio.h>
void main()
{
int a=100;
clrscr();
printf("\n mark1= ");
scanf("%d",&a);
switch(a/10)
{
case 0:
printf(" d class");
break;
case 1:
case 2:
case 3:
printf("c class");
break;
case 4:
case 5:
printf(" b class");
break;
case 6:
case 7:
case 8:
case 9:
case 10:
printf("a class");
break;
}
getch();
}

NESTED IF PROGRAMMING EXAMPLE

**NESTED PROGRAME**

===================


Nested If statement means to use the if statement inside the other if statement. Here we are providing you an example using Nested-If statement

Program:

#include<studio.h>
#include<conio.h>
void main()
{
int x,y,z,max;
clrscr();
printf("\n x= ");
scanf("%d", &x);
printf("\n y= ");
scanf("%d", &y);
printf("\n z= ");
scanf("%d", &z);
if(x>y)
{
if(x>z)
{
max=x;
}
else
{
option2:
max =z
if(y>z)
}
max=y
max=z
}
else
{
if(y>z)
option1:
{
(x>y);(x>z)
max=y;
max=x;
max=z;
}
else{
max=z
}
}
printf("The Biggest number is %d", max);
getch();
}

Output:

x=20
y=30
z=50

The biggest number is 50


Buy it

IF AND ELSE PROGRAMMING EXAMPLE

**IF & ELSE PROGRAME**
=====================

#include<studio.h>
#include<conio.h>
void main()
{
int x,y,max;
clrscr();
printf("\n mark1= ");
scanf("%d", &x);
printf("\n mark2= ");
scanf("%d", &y);
if(x>35 && y>35);
{
printf("PASS");
]
else
{
printf("FAIL");
}
getch()
}

DIVISIBLE NUMBERS USING C

**DIVISIBLE NUMBERS**
=====================

#include<studio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n a=");
scanf("%d",&a);
if(a%7==0)
{
printf("\n The Number is Divisible by 7");
}
else
{
printf("\n The Number is not Divisible by 7");
}
getch();
}

ODD OR EVEN NUMBERS USING C

**ODD OR EVEN NUMBERS**
=======================

#include<studio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n a=");
scanf("%d",&a);
if(a%2=0)
{
printf("\n Even Numbers");
}
else
{
printf("\n Odd Numbers");
}
getch();
}

BETWEEN NUMBERS USING C

**BETWEEN NUMBERS**
====================

#include<studio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n a= ");
scanf("%d", &a);
if (a==1)
{
printf("\n one");
}
elseif(a==2)
{
printf("\n two");
}
elseif(a==3)
{
printf("\n three");
}
elseif(a==4)
}
printf("\n four");
}
elseif(a==5)
{
printf("\n five");
}
else
{
printf("\n The Number is not between 1 to 5");
}
getch();
}

circle radius using c

#include<stdio.h>
#include<conio.h>
void main()
{
float a,r;
printf("\n Enter the Radious:");
scanf("%f", &r);
a=pi*r*r;
printf("\n area of the cicrle is %f", a);
getch(0;
}

Enter the radius :4
area of circle:50.12

add two no using c

** ADD TWO NO's**
=================
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n ENTER THE tWO nUMBERS:");
scanf("%d%d", &a,&b);
c-a<b;
printf("\n a,b = %d", c);
getch();
}
enter the two number : 10 20 c=30

getdta() in c

getdta() gets disk-transfer address
Declaration:
char far *getdta(void);
Remarks:
getdta returns the current setting of the disk transfer address (DTA).
Return Value:
getdta returns a far pointer to the current DTA
Program


#include <dos.h>
#include <stdio.h>

int main(void)
{
   char far *dta;

   dta = getdta();
   printf("The current disk transfer address is: %Fp\n", dta);
   return 0;
}

_dos_freemem() in c

_dos_freemem() Frees a previously allocated DOS memory block
Declaration:
unsigned _dos_freemem(unsigned segx);
Remarks:
_dos_freemem frees a memory block allocated by a previous call to _dos_allocmem.
segx is the segment address of the block.
Return Value:
On success, both functions return 0 On error,_dos_freemem returns the DOS error code and sets errno to
ENOMEM (Bad memory pointer) freemem returns -1 and sets errno to ENOMEM (Insufficient memory)

Program



 #include <dos.h>
#include <stdio.h>

int main(void)
{
  unsigned int size, segp, err, maxb;
  size = 64; /* (64 x 16) = 1024 bytes */
  err = _dos_allocmem(size, &segp);
  if (err == 0)
    printf("Allocated memory at segment: %x\n", segp);
  else {
    perror("Unable to allocate block");
    printf("Maximum no. of paragraphs available is %u\n", segp);
    return 1;
  }
  if (_dos_setblock(size * 2, segp, &maxb) == 0)
    printf("Expanded memory block at segment: %X\n", segp);
  else {
    perror("Unable to expand block");
    printf("Maximum no. of paragraphs available is %u\n", maxb);
  }
  _dos_freemem(segp);
  return 0;
}

freemem() in c

Frees a previously allocated DOS memory block
Declaration:
int freemem(unsigned segx);
Remarks:
freemem frees a memory block allocated by a previous call to allocmem.
segx is the segment address of the block.

Return Value:
On success, both functions return 0
On error,
_dos_freemem returns the DOS error code and sets errno to ENOMEM (Bad memory pointer)
freemem returns -1 and sets errno to ENOMEM (Insufficient memory)

program



#include <dos.h>
#include <alloc.h>
#include <stdio.h>

int main(void)
{
   unsigned int size, segp;
   int stat;

   size = 64; /* (64 x 16) = 1024 bytes */
   stat = allocmem(size, &segp);
   if (stat < 0)
      printf("Allocated memory at segment: %x\n", segp);
   else
      printf("Failed: maximum number of\
             paragraphs available is %u\n", stat);
   freemem(segp);

   return 0;
}

enable


   Macros that disable and enable interrupts

 Declaration:


    void enable(void);
   void _enable(void);

 Remarks:


These macros provide programmers with flexible hardware interrupt control.

   enable and _enable enable interrupts,
    allowing any device interrupts to occur.

Only the NMI (non-maskable interrupt) is allowed from any external device.

 Return Value:
 None

program


#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C    /* The clock tick
                        interrupt */

#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

void interrupt (*oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS) /* if C++, need the the ellipsis */
{
/* disable interrupts during the handling of the interrupt */
   disable();
/* increase the global counter */
   count++;
/* reenable interrupts at the end of the handler */
   _enable();
/* call the old routine */
   oldhandler();
}

int main(void)
{
/* save the old interrupt vector */
   oldhandler = _dos_getvect(INTR);

/* install the new interrupt handler */
   _dos_setvect(INTR, handler);

/* loop until the counter exceeds 20 */
   while (count < 20)
      printf("count is %d\n",count);

/* reset the old interrupt handler */
   _dos_setvect(INTR, oldhandler);

   return 0;
}

disable


 Macros that disable and enable interrupts

 Declaration:


   void disable(void);
   void _disable(void);

 Remarks:
These macros provide programmers with flexible hardware interrupt control.
  disable and _disable disable interrupts.

    allowing any device interrupts to occur.

Only the NMI (non-maskable interrupt) is allowed from any external device.

 Return Value:
 None

program


#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C    /* The clock tick
                        interrupt */

#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

void interrupt (*oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS)
 /* if C++, need the the ellipsis */
{
/* disable interrupts during the handling of the interrupt */
   disable();
/* increase the global counter */
   count++;
/* reenable interrupts at the end of the handler */
   enable();
/* call the old routine */
   oldhandler();
}

int main(void)
{
/* save the old interrupt vector */
   oldhandler = getvect(INTR);

/* install the new interrupt handler */
   setvect(INTR, handler);

/* loop until the counter exceeds 20 */
   while (count < 20)
      printf("count is %d\n",count);

/* reset the old interrupt handler */
   setvect(INTR, oldhandler);

   return 0;
}

delay


 Suspends execution for interval (milliseconds)

 Declaration: 

 void delay(unsigned milliseconds);

 Remarks:


With a call to delay, the current program is suspended from execution for
the time specified by the argument milliseconds.

It is not necessary to make a calibration call to delay before using it.

delay is accurate to one millisecond.

 Return Value:
None

 Example:

 /* Emits a 440-Hz tone for 500 milliseconds */
 #include <dos.h>

 int main(void)
 {
    sound(440);
    delay(500);
    nosound();

    return 0;
 }

bdos


 Accesses DOS system calls

 Declaration:

 int bdos(int dosfun, unsigned dosdx, unsigned dosal);

 Remarks:


bdos provides direct access to many of the DOS system calls.

See your DOS reference manuals for details on each system call.

 Use bdos for system calls that require an integer argument.
 Use bdosptr if system calls require a pointer argument; this is
   important in the large data models (compact, large, and huge).


Example:

 #include <stdio.h>
 #include <dos.h>

 /* Get current drive as 'A', 'B', ... */
 char current_drive(void)
 {
    char curdrive;

    /* Get current disk as 0, 1, ... */
    curdrive = bdos(0x19, 0, 0);
    return('A' + curdrive);
 }

 int main(void)
 {
    printf("The current drive is %c:\n", current_drive());
    return 0;
 }

allocmem


 Allocates DOS memory segment

 Declaration:


   int allocmem(unsigned size, unsigned *segp);

 Remarks:




allocmem and _dos_allocmem use the DOS system call 0x48 to allocate a block
of free memory and return the segment address of the allocated block.


If not enough room is available,   allocmem makes no assignment to the word *segp
   _dos_allocmem stores the size of the largest
    available block in the word *segp.

All allocated blocks are paragraph-aligned.


 Return Value:


  On success,
      allocmem returns -1
      _dos_allocmem returns 0
   On error,
      allocmem returns the size of the largest available block and
       sets both _doserrno and errno to ENOMEM  (Not enough memory)
      _dos_allocmem returns the DOS error code and sets errno to ENOMEM

program

#include <dos.h>
#include <alloc.h>
#include <stdio.h>

int main(void)
{
  unsigned int size, segp;
  int stat;

  size = 64;                    /* (64 x 16) = 1024 bytes */
  stat = allocmem(size, &segp);
  if (stat == -1)
    printf("Allocated memory at segment: %x\n", segp);
  else
    printf("Failed: maximum number of paragraphs available is %u\n", stat);

  return 0;
}

absread in c


 <a href="http://gan.doubleclick.net/gan_click?lid=41000000035692252&pubid=21000000000397534">Absread</a> reads absolute disk sectors

 Declaration:
   int absread(int drive, int nsects, long lsect, void *buffer);

 Remarks:


  absread uses DOS interrupt 0x25 to read specific disk sectors.

Both functions ignore the logical structure of a disk and pay no attention
to files, FATs, or directories.

If used improperly, abswrite can overwrite files, directories, and FATs.
The number of sectors to read (or write) is limited to 64K or the size of
the buffer, whichever is smaller.

 Return Value:
   On success, both return 0.
   On error, both return -1 and set errno to the value of the AX register
    returned by the system call.

 Example (absread only):

 /* absread example */

 #include <stdio.h>
 #include <conio.h>
 #include <process.h>
 #include <dos.h>

 int main(void)
 {
   int i, strt, ch_out, sector;
   char buf[512];

   printf("Insert a diskette into drive A and press any key\n");
   getch();
   sector = 0;
   if (absread(0, 1, sector, &buf) != 0)
   {
      perror("Disk problem");
      exit(1);
   }
   printf("Read OK\n");
   strt = 3;
   for (i=0; i<80; i++)
   {
      ch_out = buf[strt+i];
      putchar(ch_out);
   }
   printf("\n");
   return(0);
 }

ungetch


 Pushes a character back to the keyboard

 Declaration:

int ungetch(int ch);

 Remarks:
ungetch pushes the character ch back to the console, causing ch to be the
next character read.

ungetch fails if it is called more than once before the next read.

 Return Value:
   On success, returns the character ch.
   On error, returns EOF.

 Example:

 #include <stdio.h>
 #include <ctype.h>
 #include <conio.h>

 int main( void )
 {
    int i=0;
    char ch;

    puts("Input an integer followed by a char:");

    /* read chars until non digit or EOF */
    while((ch = getche()) != EOF && isdigit(ch))
       i = 10 * i + ch - 48; /* convert ASCII into int value */

    /* if non digit char was read, push it back into input buffer */
    if (ch != EOF)
       ungetch(ch);

    printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
    return 0;
 }

wherex, wherey



<a href="http://gan.doubleclick.net/gan_click?lid=41000000035692252&pubid=21000000000397534">wherex</a> gives current horizontal cursor position
   wherey gives current vertical cursor position

 Declaration:
   int wherex(void);
   int wherey(void);

 Remarks:


 wherex returns the x-coordinate of the current cursor position (within the
current text window).

 wherey returns the y-coordinate of the current cursor position (within the
current text window).

 Return Value:


   wherex returns an integer in the range 1 to 80.
   wherey returns an integer in the range 1 to 25,
    1 to 43, or 1 to 50.


 Example:

 #include <conio.h>

 int main(void)
 {
    clrscr();
    gotoxy(10,10);
    cprintf("Current location is X: %d  Y: %d\r\n", wherex(), wherey());
    getch();

    return 0;
 }


gettextinfo



 Gets text-mode video information

 Declaration:

 void gettextinfo(struct text_info *r);

 Remarks:
gettextinfo fills in a structure with the current text video information.

 Return Value:
gettextinfo does not return. The results are returned in the structure *r.


 Example:

 #include <conio.h>

 int main(void)
 {
    struct text_info ti;
    gettextinfo(&ti);
    cprintf("window left      %2d\r\n",ti.winleft);
    cprintf("window top       %2d\r\n",ti.wintop);
    cprintf("window right     %2d\r\n",ti.winright);
    cprintf("window bottom    %2d\r\n",ti.winbottom);
    cprintf("attribute        %2d\r\n",ti.attribute);
    cprintf("normal attribute %2d\r\n",ti.normattr);
    cprintf("current mode     %2d\r\n",ti.currmode);
    cprintf("screen height    %2d\r\n",ti.screenheight);
    cprintf("screen width     %2d\r\n",ti.screenwidth);
    cprintf("current x        %2d\r\n",ti.curx);
    cprintf("current y        %2d\r\n",ti.cury);
    return 0;
 }


getche


  getche gets a character from console, and echoes to the screen

 Declaration:


   int getche(void);

 Remarks:
getche reads a single character from the keyboard and echoes it to the
current text window, using direct video or BIOS.

 Return Value:
Both functions return the character read from the keyboard.

program


#include <stdio.h>
#include <conio.h>

int main(void)
{
   char ch;

   printf("Input a character:");
   ch = getche();
   printf("\nYou input a '%c'\n", ch);
   return 0;
}

}

gettext


   gettext copies text from text-mode screen to memory

  Declaration:


   int gettext(int left, int top, int right, int bottom, void*destin);

 Remarks:
 gettext stores the contents of an onscreen text rectangle defined by
(left, top) and (right, bottom) into the area of memory *destin.

gettext reads the rectangle's contents into memory (and puttext puts the
stored contents into the rectangle) SEQUENTIALLY from left to right and top
to bottom.


 Return Value:


   On success,
      gettext returns 1
 
  On error, both functions return 0 (for
    example, if you gave coordinates outside
    the range of the current screen mode)

Program
#include <conio.h>

char buffer[4096];

int main(void)
{
   int i;

   clrscr();
   for (i = 0; i <= 20; i++)
      cprintf("Line #%d\r\n", i);
   gettext(1, 1, 80, 25, buffer);

   gotoxy(1, 25);
   cprintf("Press any key to clear screen...");
   getch();
   clrscr();
   gotoxy(1, 25);
   cprintf("Press any key to restore screen...");
   getch();
   puttext(1, 1, 80, 25, buffer);
   gotoxy(1, 25);
   cprintf("Press any key to quit...");
   getch();

   return 0;
}


getpass


 Reads a password

 Declaration:

 char *getpass(const char *prompt);

 Remarks:
getpass reads a password from the system console, after prompting with the
null-terminated string prompt and disabling the echo.

It returns a pointer to a null-terminated string of up to eight characters
(not counting the null terminator).

 Return Value:
Returns a pointer to a static string that is overwritten with each call.

 Example:

 #include <conio.h>

 int main(void)
 {
    char *password;

    password = getpass("Input a password:");
    cprintf("The password is: %s\r\n", password);
    return 0;
 }

cputs


Writes a string to the text window on the screen

 Declaration:
  int <a href="http://gan.doubleclick.net/gan_click?lid=41000000035692252&pubid=21000000000397534">cputs</a>(const char *str);

 Remarks:


cputs writes the null-terminated string str to the current text window. It
does not append a newline character.

The string is written either directly to screen memory or by way of a BIOS
call, depending on the value of directvideo.

cputs does not translate linefeed characters (\n) into
carriage-return/linefeed character pairs (\r\n).

 Return Value:


Returns the last character printed.

 Example:

 #include <conio.h>

 int main(void)
 {
    /* clear the screen */
    clrscr();

    /* create a text window */
    window(10, 10, 80, 25);

    /* output some text in the window */
    cputs("This is within the window\r\n");

    /* wait for a key */
    getch();
    return 0;
 }

getch


 getch gets a character from console but does not echo to the screen

 Declaration:


   int getch(void);
 
 Remarks:


getch reads a single character directly from the keyboard, without echoing
to the screen.

 Return Value:


Both functions return the character read from the keyboard.

Progarm


#include <conio.h>
#include <stdio.h>

int main(void)
{
  int c;
  int extended = 0;
  c = getch();
  if (!c)
    extended = getch();
  if (extended)
    printf("The character is extended\n");
  else
    printf("The character isn't extended\n");

  return 0;

delline


 (Text mode): Deletes line in text window


 Declaration:
 void delline(void);

 Remarks:
delline deletes the line containing the cursor and moves all lines below it
one line up.

delline operates within the currently active text window.

 Return Value:
 None



 Example:

 #include <conio.h>

 int main(void)
 {
    clrscr();
    cprintf("The function DELLINE deletes the line containing the\r\n");
    cprintf("cursor and moves all lines below it one line up.\r\n");
    cprintf("DELLINE operates within the currently active text\r\n");
    cprintf("window.  Press any key to continue . . .");
    gotoxy(1,2);  /* Move the cursor to the second line and first column */
    getch();

    delline();
    getch();

    return 0;
 }

clrscr


 Clears text mode window

 Declaration:
void clrscr(void);

 Remarks:


clrscr clears the current text window and places the cursor in the upper
left-hand corner (at position 1,1).

 Return Value:
 None




 Example:

 #include <conio.h>

 int main(void)
 {
    int i;

    clrscr();
    for (i = 0; i < 20; i++)
       cprintf("%d\r\n", i);
    cprintf("\r\nPress any key to clear screen");
    getch();

    clrscr();
    cprintf("The screen has been cleared!");
    getch();

    return 0;
 }

clreol


 Clears to end of line in text window

 Declaration:

void <a href="http://gan.doubleclick.net/gan_click?lid=41000000035692252&pubid=21000000000397534">clreol</a>(void);

 Remarks:


clreol clears all characters from the cursor position to the end of the line
within the current text window, without moving the cursor.

 Return Value:

None


 Example:

 #include <conio.h>

 int main(void)

 {
    clrscr();
    cprintf("The function CLREOL clears all characters from the\r\n");
    cprintf("cursor position to the end of the line within the\r\n");
    cprintf("current text window, without moving the cursor.\r\n");
    cprintf("Press any key to continue . . .");
    gotoxy(14, 4);
    getch();

    clreol();
    getch();

    return 0;
 }

cgets


 Reads string from console

 Declaration:

char *cgets(char *str);

 Remarks:
cgets reads a string of characters from the console and stores the string
(and the string length) in the location *str.

Before you call cgets, set str[0] to the maximum length of the string to be
read.

cgets reads characters until it encounters a carriage-return/linefeed
combination (CR/LF), or until the maximum allowable number of characters
have been read.

If cgets reads a CR/LF, it replaces the CR/LF with a \0 (null terminator)
before storing the string.

On return, str[1] is set to the number of characters actually read.

The characters read start at str[2] and end with a null terminator, so str
must be at least (str[0] + 2) bytes long.

 Return Value:
   On success, returns a pointer to str[2].


 Example:

 #include <stdio.h>
 #include <conio.h>

 int main(void)
 {
    char buffer[83];
    char *p;

    /* There's space for 80 characters plus the NULL terminator */
    buffer[0] = 81;

    printf("Input some chars:");
    p = cgets(buffer);
    printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);
    printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);

    /* Leave room for 5 characters plus the NULL terminator */
    buffer[0] = 6;

    printf("Input some chars:");
    p = cgets(buffer);
    printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);
    printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);
    return 0;
 }