C language library function (P class letters)

xiaoxiao2021-03-06  41

Function name: PARSFNM

Function: Analysis File Name

Usage: char * PARSFNM (Char * Cmdline, Struct FCB * fcbptr, int option);

Example:

#include

#include

#include

#include

Int main (void)

{

Char line [80];

Struct FCB BLK;

/ * Get file name * /

Printf ("Enter Drive and File Name (No Path - IE. A: File.dat) / N");

Gets (line);

/ * PUT FILE Name in FCB * /

IF (PARSFNM (Line, & BLK, 1) == NULL)

Printf ("Error In Parsfm Call / N);

Else

Printf ("DRIVE #% D Name:% 11S / N", BLK.FCB_DRIVE, BLK.FCB_NAME;

Return 0;

}

Function name: peek

Function: Check storage unit

Usage: INT PEEK (Int segment);

Example:

#include

#include

#include

Int main (void)

{

INT value = 0;

Printf ("THE CURRENT Status of Your Keyboard IS: / N");

Value = peek (0x0040, 0x0017);

IF (Value & 1)

Printf ("Right Shift On / N");

Else

Printf ("Right SHIFT OFF / N");

IF (Value & 2)

Printf ("LEFT SHIFT ON / N");

Else

Printf ("LEFT SHIFT OFF / N");

IF (Value & 4)

Printf ("Control Key ON / N");

Else

Printf ("Control Key Off / N");

IF (Value & 8)

Printf ("Alt Key ON / N");

Else

Printf ("Alt Key Off / N");

IF (Value & 16)

Printf ("Scroll Lock ON / N");

Else

Printf ("Scroll Lock Off / N";

IF (Value & 32)

Printf ("NUM LOCK ON / N");

Else

Printf ("NUM LOCK OFF / N");

IF (Value & 64)

Printf ("Caps Lock ON / N");

Else

Printf ("Caps Lock Off / N");

Return 0;

}

Function name: peekb

Function: Check storage unit

Usage: CHAR Peekb (int segment, unsigned offset);

Example:

#include

#include

#include

Int main (void)

{

INT value = 0;

Printf ("THE CURRENT Status of Your Keyboard IS: / N");

Value = peekb (0x0040, 0x0017);

IF (Value & 1)

Printf ("Right Shift On / N");

Else

Printf ("Right SHIFT OFF / N");

IF (Value & 2)

Printf ("LEFT SHIFT ON / N");

Else

Printf ("LEFT SHIFT OFF / N");

IF (Value & 4)

Printf ("Control Key ON / N");

Else

Printf ("Control Key Off / N");

IF (Value & 8)

Printf ("Alt Key ON / N");

Else

Printf ("Alt Key Off / N");

IF (Value & 16)

Printf ("Scroll Lock ON / N");

Else

Printf ("Scroll Lock Off / N";

IF (Value & 32)

Printf ("NUM LOCK ON / N");

Else

Printf ("NUM LOCK OFF / N");

IF (Value & 64)

Printf ("Caps Lock ON / N");

Else

Printf ("Caps Lock Off / N");

Return 0;

}

Function name: Perror

Function: System error message

Usage: Void Perror (Char * String);

Example:

#include

Int main (void)

{

File * fp;

fp = fopen ("PERROR.DAT", "R");

IF (! fp)

"Unable to open file forread");

Return 0;

}

Function name: Piemelice

Function: Draw and populate a fan

Usage: Void Far Piemelice (int X, int Stanle, int endangle, int RADIUS);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int midx, midy;

INT Stangle = 45, endangle = 135, radius = 100;

/ * Initialize Graphics and Local Variables * /

INITGRAPH (& GDriver, & gmode, ");

/ * Read Result of Initization * /

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;

/ * SET FILL STYLE AND DRAW A PIE SLICE * /

SetFillStyle (Empty_Fill, getMaxColor ());

Pieslice (MIDX, Midy, Stangle, Endangle, RADIUS);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: Poke

Function: save the value to a given storage unit

Usage: Void Poke (int segment, int offset, int value);

Example:

#include

#include

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;

}

Function name: pokeb

Function: save the value to a given storage unit

Usage: void pokeb (int segment, int offset, char value);

Example:

#include

#include

Int main (void)

{

CLRSCR ();

CPRINTF ("Make Sure The Scroll Lock Key IS Off and Press Any Key / R / N");

Getch ();

Pokeb (0x0000, 0x0417, 16);

CPRINTF ("THE SCROLL LOCK IS NOW ON / R / N);

Return 0;

}

Function name: poly

Function: Generate a polynomial according to parameters

Usage: Double Poly (Double X, INT N, Double C []);

Example:

#include

#include

/ * POLYNOMIAL: X ** 3 - 2X ** 2 5X - 1 * /

Int main (void)

{

Double array [] = {-1.0, 5.0, -2.0, 1.0};

Double Result;

Result = POLY (2.0, 3, array);

Printf ("The Polynomial: x ** 3 - 2.0x ** 2 5X - 1 AT 2.0 IS% LF / N",

Result;

Return 0;

}

Function name: POW

Function: Index function (X of X)

Usage: Double Pow (Double X, Double Y);

Example:

#include

#include

Int main (void)

{

Double x = 2.0, y = 3.0;

Printf ("% lf raised to% LF IS% LF / N", X, Y, POW (X, Y)); RETURN 0;

}

Function name: Pow10

Function: Index function (10 P movable)

Usage: Double Pow10 (INT P);

Example:

#include

#include

Int main (void)

{

Double P = 3.0;

Printf ("Ten Raised TO% LF IS% LF / N", P, POW10 (P));

Return 0;

}

Function name: Printf

Function: Generate a function of formatting output

Usage: int printf (char * format ...);

Example:

#include

#include

#define i 555

#define r 5.5

Int main (void)

{

INT I, J, K, L;

Char BUF [7];

Char * prefix = buf;

Char TP [20];

Printf ("prefix 6d 6o 8x 10.2e"

"10.2f / n");

STRCPY (Prefix, "%");

For (i = 0; i <2; i )

{

For (j = 0; j <2; j )

For (k = 0; k <2; k )

For (l = 0; l <2; l )

{

IF (i == 0) STRCAT (Prefix, "-");

IF (j == 0) STRCAT (Prefix, " ");

IF (k == 0) STRCAT (Prefix, "#");

IF (l == 0) STRCAT (Prefix, "0");

Printf ("% 5s |", prefix;

STRCPY (TP, prefix);

STRCAT (TP, "6D |");

Printf (TP, I);

STRCPY (TP, ");

STRCPY (TP, prefix);

STRCAT (TP, "6o |");

Printf (TP, I);

STRCPY (TP, ");

STRCPY (TP, prefix);

STRCAT (TP, "8x |");

Printf (TP, I);

STRCPY (TP, ");

STRCPY (TP, prefix);

STRCAT (TP, "10.2e |");

Printf (TP, R);

STRCPY (TP, prefix);

STRCAT (TP, "10.2F |");

Printf (TP, R);

Printf ("/ n");

STRCPY (Prefix, "%");

}

}

Return 0;

}

Function name: PUTC

Function: Output a character in the specified stream

Usage: int PUTC (INT CH, File * Stream);

Example:

#include

Int main (void)

{

Char msg [] = "Hello WORLD / N";

INT i = 0;

While (MSG [i])

PUTC (MSG [i ], stdout; return 0;

}

Function name: PUTCH

Function: Output Character to Console

Usage: int PUTCH (INT CH);

Example:

#include

#include

Int main (void)

{

CHAR CH = 0;

Printf ("INPUT A String:");

While ((ch! = '/ r')))))

{

CH = GetCh ();

PUTCH (CH);

}

Return 0;

}

Function name: Putchar

Function: Output characters on STDOUT

Usage: int Putchar (int CH);

Example:

#include

/ * Define Some Box-Drawing Characters * /

#define left_top 0xDA

#define right_top 0xBF

#define horiz 0xc4

#define Vert 0xB3

#define left_bot 0xc0

#define right_bot 0xd9

Int main (void)

{

CHAR I, J;

/ * DRAW the top of the box * /

Putchar (Left_top);

For (i = 0; i <10; i )

PUTCHAR (HORIZ);

Putchar (right_top);

PUTCHAR ('/ n');

/ * DRAW THE MIDDLE * /

For (i = 0; i <4; i )

{

Putchar (VERT);

For (j = 0; j <10; j )

PUTCHAR ('');

Putchar (VERT);

PUTCHAR ('/ n');

}

/ * DRAW the bottom * /

Putchar (left_bot);

For (i = 0; i <10; i )

PUTCHAR (HORIZ);

Putchar (right_bot);

PUTCHAR ('/ n');

Return 0;

}

Function name: Putenv

Function: add string to the current environment

Usage: int Putenv (char * envvar);

Example:

#include

#include

#include

#include

#include

Int main (void)

{

CHAR * PATH, * PTR;

INT i = 0;

/ * Get the current path environment * /

PTR = GetENV ("path");

/ * SET UP New Path * /

Path = Malloc (Strlen (PTR) 15);

STRCPY (PATH, "PATH =");

STRCAT (PATH, PTR);

STRCAT (PATH, "; C: // Temp");

/ * Replace The Current Path and Display Current Environment * /

Putenv (PATH);

While (Environ [i])

Printf ("% s / n", environ [i ]);

Return 0;

}

Function name: PUTIMAGE

Function: Output a bitmap on the screen

Usage: Void Far Putimage (int X, int y, void far * bitmap, int su);

Example:

#include

#include

#include

#include

#define arrow_size 10

Void Draw_arrow (int X, int y);

Int main (void)

{

/ * Request Autodetection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Void * arrow;

INT X, Y, MAXX;

Unsigned int size;

/ * Initialize Graphics and Local Variables * /

INITGRAPH (& GDriver, & gmode, ");

/ * Read Result of Initization * /

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

}

Maxx = getmaxx ();

X = 0;

y = getmaxy () / 2;

/ * DRAW the image to be grabbed * /

Draw_arrow (x, y);

/ * Calculate the size of the image * /

SIZE = Imagesize (x, y-arrow_size, x (4 * arrow_size), y arrow_size);

/ * Allocate Memory To Hold The Image * /

Arrow = malloc (size);

/ * GRAB the image * /

GetImage (x, y-arrow_size, x (4 * arrow_size), y arrow_size, arrow;

/ * Repeat Until a key ispess * /

While (! kbhit ())

{

/ * ERASE OLD Image * /

PUTIMAGE (X, Y-arrow_size, arrow, xor_put);

X = arrow_size;

IF (x> = maxx)

X = 0;

/ * Plot new image * /

PUTIMAGE (X, Y-arrow_size, arrow, xor_put);

}

/ * Clean Up * /

FREE (arrow);

Closegraph ();

Return 0;

}

Void Draw_arrow (int x, int y)

{

/ * Draw an arrow on the screen * /

Moveto (X, Y);

Lineerel (4 * arrow_size, 0);

Lineerel (-2 * arrow_size, -1 * arrow_size);

LineRel (0, 2 * arrow_size);

Lineerel (2 * arrow_size, -1 * arrow_size);

}

Function name: PUTPIXEL

Function: Draw a pixel in the designated location

Usage: Void Far Putpixel (int X, int y, int pixelcolor);

Example:

#include

#include

#include

#include

#include

#define pixel_count 1000

#define delay_time 100 / * in milliseconds * /

Int main (void)

{

/ * Request Autodetection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT I, X, Y, Color, Maxx, Maxy, MaxColor, SEED

/ * Initialize Graphics and Local Variables * /

INITGRAPH (& GDriver, & gmode, ");

/ * Read Result of Initization * /

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

}

Maxx = getmaxx () 1;

MAXY = getMaxy () 1;

MaxColor = getMaxColor () 1;

While (! kbhit ())

{

/ * Seed the random number generator * /

SEED = Random (32767);

SRAND (SEED);

For (i = 0; i

{

X = random (maxx);

Y = random (MAXY);

Color = random (maxcolor);

PUTPIXEL (X, Y, Color);

}

DELAY (Delay_Time);

SRAND (SEED);

For (i = 0; i

{

X = random (maxx);

Y = random (MAXY);

Color = random (maxcolor);

IF (color == getpixel (x, y))

Putpixel (x, y, 0);

}

}

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: PUTS

Function: send a string to the stream

Usage: int PUTS (Char * String);

Example:

#include

Int main (void)

{

Char string [] = "this is an example output string / n";

PUTS (STRING);

Return 0;

}

Function name: Puttext

Function: copy text from the storage area to the screen

Usage: int PutText (int LEFT, INT TOP, INT RIGHT, INT BOTTOM, VOID * SOURCE);

#include

Int main (void)

{

Char buffer [512];

/ * Put Some text to the console * /

CLRSCR ();

gotoxy (20, 12);

CPRINTF ("this is a test. press any key to contact ...");

Getch ();

/ * Grab screen contents * /

GetText (20, 12, 36, 21, buffer);

CLRSCR ();

/ * Put selected characters back to the screen * /

gotoxy (20, 12);

Puttext (20, 12, 36, 21, buffer);

Getch ();

Return 0;

}

Function name: PUTW

Function: send a character or word to the stream

Usage: int PUTW (int W, file * stream);

Example:

#include

#include

#define fname "Test. $$$"

Int main (void)

{

File * fp;

Int word;

/ * Place the Word in a file * /

FP = fopen (FNAME, "WB");

IF (fp == null)

{

Printf ("Error Opening File% S / N", FNAME);

Exit (1);

}

Word = 94;

PUTW (Word, FP);

IF (FERROR (FP))

Printf ("Error Writing to File / N);

Else

Printf ("Successful Write / N);

Fclose (fp);

/ * Reopen THE FILE * /

fp = fopen (FNAME, "RB");

IF (fp == null)

{

Printf ("Error Opening File% S / N", FNAME);

Exit (1);

}

/ * Extract the word * /

Word = getW (fp);

IF (FERROR (FP))

Printf ("ERROR READING FILE / N");

Else

Printf ("Successful Read: Word =% D / N", Word;

/ * Clean Up * /

Fclose (fp);

Unlink (FNAME);

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-74411.html

New Post(0)