C Language Library functions (class B letters)

Source: Internet
Author: User
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 <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> 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<user_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 <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h> 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<user_fill; i++)
{
/* Set the Fill style */
Setfillstyle (i, Getmaxcolor ()); /* Draw the-the-bar */
Bar3d (midx-50, midy-50, Midx+50, Midy+50, 10, 1); Getch ();
}/* Clean up */
Closegraph ();
return 0;
}
Function Name: BDOs
Function: DOS system call
Usage: int bdos (int dosfun, unsigned dosdx, unsigned dosal);
Program 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;
}
Function Name: bdosptr
Function: DOS system call
Usage: int bdosptr (int dosfun, void *argument, unsigned dosal);
Program Example: #include <string.h>

#include <stdio.h>
#include <dir.h>
#include <dos.h>
#include <errno.h>
#include <stdlib.h> #define Buflen 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 <bios.h>
#include <conio.h> #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: Soft hard disk I/O
Usage: int biosdisk (int cmd, int drive, int head, int track, int sector
int nsects, void *buffer);
Program Example: #include <bios.h>
#include <stdio.h> int main (void)
{
int result;
Char buffer[512]; printf ("Testing to see if drive A:is ready\n");
result = Biosdisk (4,0,0,0,0,1,buffer);
Result &= 0x02;
(result)? (printf ("Drive A:ready\n")):
(printf ("Drive A:not ready\n")); return 0;
}
Function Name: Biosequip
function: Check Equipment
Usage: int biosequip (void);
Program Example: #include <bios.h>
#include <stdio.h> int main (void)
{
int result;
Char buffer[512]; printf ("Testing to see if drive A:is ready\n");
result = Biosdisk (4,0,0,0,0,1,buffer);
Result &= 0x02;
(result)? (printf ("Drive A:ready\n")):
(printf ("Drive A:not ready\n")); return 0;
}
Function Name: Bioskey
Function: Keyboard interface for direct use of the BIOS service
Usage: int bioskey (int cmd);
Program Example: #include <stdio.h>
#include <bios.h>
#include <ctype.h> #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 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: Returns the storage block size
Usage: int biosmemory (void);
Program Example: #include <stdio.h>
#include <bios.h> int main (void)
{
int memory_size; Memory_size = Biosmemory (); /* Returns value up to 640K */
printf ("RAM size =%dk\n", memory_size);
return 0;
}
Function Name: Biosprint
Function: Printer I/o directly using the BIOS service
Usage: int biosprint (int cmd, int byte, int port);
Program Example: #include <stdio.h>
#include <conio.h>
#include <bios.h> 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 BIOS time
Usage: long biostime (int cmd, long newtime);
Program Example: #include <stdio.h>
#include <bios.h>
#include <time.h>
#include <conio.h> int main (void)
{
Long Bios_time; CLRSCR ();
cprintf ("The number of the 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 data segment space allocation
Usage: int brk (void *endds);
Program Example: #include <stdio.h>
#include <alloc.h> 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
Function: Search by dichotomy
Usage: void *bsearch (const void *key, const void *base, size_t *nelem,
size_t width, int (*fcmp) (const void *, const *));
Program Example: #include <stdlib.h>
#include <stdio.h> #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 at
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 ("In the table.\n");
Else
printf ("T in the table.\n"); return 0;
}

The above is the C language library function (class B letter) content, more related articles please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.