C language library function Daquan (letter B) --- instructions for use)

Source: Internet
Author: User
C language library function Daquan (letter B) --- instructions for use (conversion) -- Linux general technology-Linux programming and kernel information, the following is read details. Function Name: bar
Function: Draw a two-dimensional bar chart
Usage: void far bar (int left, int top, int right, int bottom );
Program example:
# Include
# Include
# Include
# Include

Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy, I;

/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");

/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s \ n", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}

Midx = getmaxx ()/2;
Midy = getmaxy ()/2;

/* Loop through the fill patterns */
For (I = SOLID_FILL; I {
/* Set the fill style */
Setfillstyle (I, getmaxcolor ());

/* Draw the bar */
Bar (midx-50, midy-50, midx + 50,
Midy + 50 );

Getch ();
}

/* Clean up */
Closegraph ();
Return 0;
}

Function Name: bar3d
Function: Draw a three-dimensional bar chart
Usage: void far bar3d (int left, int top, int right, int bottom,
Int depth, int topflag );
Program example:

# Include
# Include
# Include
# Include

Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy, I;

/* Initialize graphics, local variables */
Initgraph (& gdriver, & gmode ,"");

/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s \ n", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with error code */
}

Midx = getmaxx ()/2;
Midy = getmaxy ()/2;

/* Loop through the fill patterns */
For (I = EMPTY_FILL; I {
/* Set the fill style */
Setfillstyle (I, getmaxcolor ());

/* Draw the 3-d bar */
Bar3d (midx-50, midy-50, midx + 50, midy + 50, 10, 1 );

Getch ();
}

/* Clean up */
Closegraph ();
Return 0;
}

Function Name: bdos
Power: DOS system call
Usage: int bdos (int dosfun, unsigned dosdx, unsigned dosal );
Program example:

# Include
# Include

/* 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;
}

Function Name: bdosptr
Power: DOS system call
Usage: int bdosptr (int dosfun, void * argument, unsigned dosal );
Program example:

# Include
# Include
# Include
# Include
# Include
# Include

# Define BUFLEN 80

Int main (void)
{
Char buffer [BUFLEN];
Int test;

Printf ("Enter full pathname of a directory \ n ");
Gets (buffer );

Test = bdosptr (0x3B, buffer, 0 );
If (test)
{
Printf ("DOS error message: % d \ n", errno );
/* See errno. h for error listings */
Exit (1 );
}

Getcwd (buffer, BUFLEN );
Printf ("The current directory is: % s \ n", buffer );

Return 0;
}

Function Name: bioscom
Function: serial I/O communication
Usage: int bioscom (int cmd, char abyte, int port );
Program example:

# Include
# Include

# Define COM1 0
# Define DATA_READY 0x100
# Define TRUE 1
# Define FALSE 0

# Define SETTINGS (0x80 | 0x02 | 0x00 | 0x00)

Int main (void)
{
Int in, out, status, DONE = FALSE;

Bioscom (0, SETTINGS, COM1 );
Cprintf ("... BIOSCOM [ESC] to exit... \ n ");
While (! DONE)
{
Status = bioscom (3, 0, COM1 );
If (status & DATA_READY)
If (out = bioscom (2, 0, COM1) & 0x7F )! = 0)
Putch (out );
If (kbhit ())
{
If (in = getch () = '\ x1B ')
DONE = TRUE;
Bioscom (1, in, COM1 );
}
}
Return 0;
}

Function Name: biosdisk
Function: Hard Disk I/O
Usage: int biosdisk (int cmd, int drive, int head, int track, int sector
Int nsects, void * buffer );
Program example:

# Include
# Include

Int main (void)
{
Int result;
Char buffer [512];

Printf ("Testing to see if drive a: is ready \ n ");
Result = biosdisk (, buffer );
Result & = 0x02;
(Result )? (Printf ("Drive A: Ready \ n ")):
(Printf ("Drive A: Not Ready \ n "));

Return 0;
}

Function Name: biosequip
Skill: Check the device
Usage: int biosequip (void );
Program example:

# Include
# Include

Int main (void)
{
Int result;
Char buffer [512];

Printf ("Testing to see if drive a: is ready \ n ");
Result = biosdisk (, buffer );
Result & = 0x02;
(Result )? (Printf ("Drive A: Ready \ n ")):
(Printf ("Drive A: Not Ready \ n "));

Return 0;
}

Function Name: bioskey
Function: Use the keyboard interface of the BIOS service directly.
Usage: int bioskey (int cmd );
Program example:

# Include
# Include
# Include

# Define RIGHT 0x01
# Define LEFT 0x02
# Define CTRL 0x04
# Define ALT 0x08

Int main (void)
{
Int key, modifiers;

/* Function 1 returns 0 until a key is pressed */
While (bioskey (1) = 0 );

/* Function 0 returns the key that is waiting */
Key = bioskey (0 );

/* Use function 2 to determine if shift keys were used */
Modifiers = bioskey (2 );
If (modifiers)
{
Printf ("[");
If (modifiers & RIGHT) printf ("RIGHT ");
If (modifiers & LEFT) printf ("LEFT ");
If (modifiers & CTRL) printf ("CTRL ");
If (modifiers & ALT) printf ("ALT ");
Printf ("]");
}
/* Print out the character read */
If (isalnum (key & 0xFF ))
Printf ("'% C' \ n", key );
Else
Printf ("% # 02x \ n", key );
Return 0;
}

Function Name: biosmemory
Function: return the size of the storage block.
Usage: int biosmemory (void );
Program example:

# Include
# Include

Int main (void)
{
Int memory_size;

Memory_size = biosmemory ();/* returns value up to 640 K */
Printf ("RAM size = % dK \ n", memory_size );
Return 0;
}

Function Name: biosprint
Power: directly use the BIOS service printer I/O
Usage: int biosprint (int cmd, int byte, int port );
Program example:

# Include
# Include
# Include

Int main (void)
{
# Define STATUS 2/* printer status command */
# Define PORTNUM 0/* port number for LPT1 */

Int status, abyte = 0;

Printf ("Please turn off your printer. Press any key to continue \ n ");
Getch ();
Status = biosprint (STATUS, abyte, PORTNUM );
If (status & 0x01)
Printf ("Device time out. \ n ");
If (status & 0x08)
Printf ("I/O error. \ n ");

If (status & 0x10)
Printf ("Selected. \ n ");
If (status & 0x20)
Printf ("Out of paper. \ n ");

If (status & 0x40)
Printf ("Acknowledge. \ n ");
If (status & 0x80)
Printf ("Not busy. \ n ");

Return 0;
}

Function Name: biostime
Function: read or set the BIOS time.
Usage: long biostime (int cmd, long newtime );
Program example:

# Include
# Include
# Include
# Include

Int main (void)
{
Long bios_time;

Clrscr ();
Cprintf ("The number of clock ticks since midnight is: \ r \ n ");
Cprintf ("The number of seconds since midnight is: \ r \ n ");
Cprintf ("The number of minutes since midnight is: \ r \ n ");
Cprintf ("The number of hours since midnight is: \ r \ n ");
Cprintf ("\ r \ nPress any key to quit :");
While (! Kbhit ())
{
Bios_time = biostime (0, 0L );

Gotoxy (50, 1 );
Cprintf ("% lu", bios_time );

Gotoxy (50, 2 );
Cprintf ("%. 4f", bios_time/CLK_TCK );

Gotoxy (50, 3 );
Cprintf ("%. 4f", bios_time/CLK_TCK/60 );

Gotoxy (50, 4 );
Cprintf ("%. 4f", bios_time/CLK_TCK/3600 );
}
Return 0;
}

Function Name: brk
Function: change the data segment space allocation
Usage: int brk (void * endds );
Program example:

# Include
# Include

Int main (void)
{
Char * ptr;

Printf ("Changing allocation with brk () \ n ");
Ptr = malloc (1 );
Printf ("Before brk () call: % lu bytes free \ n", coreleft ());
Brk (ptr + 1000 );
Printf ("After brk () call: % lu bytes free \ n", coreleft ());
Return 0;
}

Function Name: bsearch
Merit: Binary Search
Usage: void * bsearch (const void * key, const void * base, size_t * nelem,
Size_t width, int (* fcmp) (const void *, const *));
Program example:

# Include
# Include

# Define NELEMS (arr) (sizeof (arr)/sizeof (arr [0])

Int numarray [] = {123,145,512,627,800,933 };

Int numeric (const int * p1, const int * p2)
{
Return (* p1-* p2 );
}

Int lookup (int key)
{
Int * itemptr;

/* The cast of (int (*) (const void *, const void *))
Is needed to avoid a type mismatch error
Compile time */
Itemptr = bsearch (& key, numarray, NELEMS (numarray ),
Sizeof (int), (int (*) (const void *, const void *) numeric );
Return (itemptr! = NULL );
}

Int main (void)
{
If (lookup (512 ))
Printf ("512 is in the table. \ n ");
Else
Printf ("512 isn' t in the table. \ n ");

Return 0;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.