C language library function (S type letters) - 2

xiaoxiao2021-03-06  41

Function name: setjmp

Function: non-local transfer

Usage: int setJMP (JMP_BUF ENV);

Example:

#include

#include

#include

Void Subroutine (Void);

JMP_buf jumper;

Int main (void)

{

Int value;

Value = setjmp (jumper);

IF (value! = 0)

{

Printf ("Longjmp with Value% D / N", Value);

exit (value);

}

Printf ("About to Call Subroutine ... / N");

Subroutine ();

Return 0;

}

Void Subroutine (Void)

{

Longjmp (Jumper, 1);

}

Function name: SetLinesTyle

Function: Set the current line width and type

Usage: Void Far SetLinesTyle (int Linestype, unsigned Upattern);

Example:

#include

#include

#include

#include

#include

/ * The names of the line style supported * /

Char * lname [] = {

"Solid_Line",

"Dotted_line",

"Center_line",

"DASHED_LINE",

"Userbit_Line"

}

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int Style, MIDX, Midy, Userpat;

Char StyleStr [40];

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

/ * A user defined line pattern * /

/ * Binary: "0000000000000001" * /

Userpat = 1;

For (Style = Solid_Line; Style <= Userbit_Line; Style )

{

/ * SELECT The line style * /

SetLinesTyle (Style, UserPat, 1);

/ * Convert Style Into a string * / strcpy (stylestr, lname [style]);

/ * Draw a line * /

LINE (0, 0, MIDX-10, Midy);

/ * Draw a rectangle * /

Rectangle (0, 0, getmaxx (), getmaxy ());

/ * OUTPUT A Message * /

OutTextxy (MIDX, Midy, StyleStr);

/ * Wait for a key * /

Getch ();

ClearDevice ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: setmem

Function: save the value to the storage area

Usage: void setmem (void * addr, int Len, char value);

Example:

#include

#include

#include

Int main (void)

{

Char * DEST;

Dest = Calloc (21, SIZEOF (CHAR));

SetMem (DEST, 20, 'C');

Printf ("% s / n", dest);

Return 0;

}

Function name: setmode

Function: Setting Open File Mode

Usage: int setmode (int Handle, unsigned mode);

Example:

#include

#include

#include

Int main (void)

{

Int result;

Result = setmode (fileno (stdprn), o_text);

IF (result == -1)

PERROR ("Mode Not Available / N);

Else

Printf ("Mode SuccessFully Switch / N");

Return 0;

}

Function name: setPalette

Function: Change the color of the palette

Usage: Void Far SetPalette (int index, int actural_color);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT Color, MaxColor, HT;

INT Y = 10;

Char msg [80];

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

MaxColor = getMaxcolor ();

HT = 2 * textheight ("w");

/ * Display the default colors * /

For (Color = 1; Color <= maxColor; Color )

{

SetColor (Color);

Sprintf (MSG, "Color:% D", Color;

Outtextxy (1, y, msg);

Y = HT;

}

/ * Wait for a key * /

Getch ();

/ * Black out the colors one by one * /

For (Color = 1; Color <= maxColor; Color )

{

SetPalette (Color, Black);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: setRGBPALETTE

Function: Define the color of the IBM8514 graphics card

Usage: Void Far SetRGBpalette (int color, int red, int wh, int blue);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * SELECT A Driver and Mode That Supports the Use * /

/ * Of the setrgbpalette function. * /

INT GDRIVER = VGA, GMODE = VGAHI, ErrorCode;

Struct PaletType Pal;

INT I, HT, Y, XMAX;

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

}

/ * GRAB a COPY OF THE PALETTE * /

GetPalette (& PAL);

/ * CREATE GRAY SCALE * /

For (i = 0; i

SetRGBPALETTE (Pal.colors [i], i * 4, i * 4, i * 4);

/ * DISPLAY THE SCALE * /

HT = getmaxy () / 16;

XMAX = getmaxx ();

y = 0;

For (i = 0; i

{

SetFillStyle (Solid_Fill, i);

BAR (0, Y, Xmax, Y HT);

Y = HT;

}

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setTextJustify

Function: Setting the text alignment for graphic functions

Usage: Void Far SetTextJustify (int horiz, int value);

Example:

#include

#include

#include

#include

/ * Function prototype * /

Void XAT (int X, int y);

/ * Horizontal Text Justification Settings * /

Char * hjust [] = {"left_text",

"Center_text",

"Right_Text"

}

/ * Vertical Text Justification Settings * /

Char * vjust [] = {"left_text",

"Center_text",

"Right_Text"

}

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int Midx, Midy, HJ, VJ;

Char msg [80];

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

/ * Loop through text justifications * /

For (hj = left_text; hj <= right_text; hj )

FOR (vj = left_text; vj <= right_text; vj )

{

ClearDevice ();

/ * SET the text justification * /

SetTextJustify (HJ, VJ);

/ * CREATE A Message String * /

Sprintf (MSG, "% S% S", hjust [hj], vjust [vj]);

/ * CREATE CROSS Hairs on the screen * /

XAT (MIDX, MIDY);

/ * OUTPUT the Message * /

OutTextxy (MIDX, MIDY, MSG);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

/ * DRAW AN "X" AT (x, y) * /

Void XAT (int X, int y)

{

LINE (X-4, Y, X 4, Y);

LINE (x, y-4, x, y 4);

}

Function name: setTextStyle

Function: Sets the current text attribute for graphic output

Usage: Void Far setTextStyle (int Font, int Direction, char size);

Example:

#include

#include

#include

#include

/ * The names of the text styles supported * /

Char * fname [] = {"Default Font",

"Triplex Font",

"Small Font",

"Sans Serif Font",

"Gothic Font"

}

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int Style, MIDX, Midy;

INT size = 1;

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

SetTextJustify (center_text, center_text);

/ * Loop through the available text styles * /

FOR (Style = default_font; style <= gothic_font; style )

{

ClearDevice ();

IF (Style == Triplex_Font)

SIZE = 4;

/ * SELECT The text style * /

SetTextStyle (style, horiz_dir, size);

/ * OUTPUT A Message * /

Outtextxy (MIDX, Midy, Fname [style]);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: setTextStyle

Function: Sets the current text attribute for graphic output

Usage: Void Far setTextStyle (int Font, int Direction, char size);

Example:

#include

#include

#include

#include

/ * The names of the text styles supported * /

Char * fname [] = {"Default Font", "Triplex Font",

"Small Font",

"Sans Serif Font",

"Gothic Font"

}

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int Style, MIDX, Midy;

INT size = 1;

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

SetTextJustify (center_text, center_text);

/ * Loop through the available text styles * /

FOR (Style = default_font; style <= gothic_font; style )

{

ClearDevice ();

IF (Style == Triplex_Font)

SIZE = 4;

/ * SELECT The text style * /

SetTextStyle (style, horiz_dir, size);

/ * OUTPUT A Message * /

Outtextxy (MIDX, Midy, Fname [style]);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: Settime

Function: Setting the system time

Usage: Void SetTime (struct time * timep);

Example:

#include

#include

Int main (void)

{

Struct Time T;

GetTime (& T);

Printf ("THE CURRENT Minute IS:% D / N", T.Ti_min);

Printf ("Tha Current Hour IS:% D / N", T.Ti_Hour;

Printf ("THE CURRENT HUNDREDTH OF A Second IS:% D / N", T.TI_HUND);

Printf ("THE Current Second IS:% D / N", T.Ti_Sec);

/ * Add one to the minutes strunt element and then call settime * /

T.TI_MIN ;

SetTime (& T);

Return 0;

}

Function name: SetuserCharsize

Function: Change the character width and height for vector font

Usage: Void Far Setusercharsize (int Multx, Int Dirx, Int Multy, INT DIRY);

#include

#include

#include

#include

Int main (void)

{

/ * Request Autodetection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

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

}

/ * SELECT A TEXTSTYLE * /

SetTextStyle (Triplex_Font, Horiz_Dir, 4);

/ * Move to the text starting position * /

MoveTo (0, getmaxy () / 2);

/ * OUTPUT SOME NORMAL TEXT * /

OutText ("NORM");

/ * Make the text 1/3 The Normal Width * /

Setusercharsize (1, 3, 1, 1);

OutText ("Short");

/ * Make The Text 3 Times Normal Width * /

SetuserCharsize (3, 1, 1, 1);

OutText ("Wide");

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setvbuf

Function: Touch the buffer with the stream

Usage: int setvbuf (File * Stream, Char * BUF, INT TYPE, Unsigned size

Example:

#include

Int main (void)

{

File * Input, * Output;

Char bufr [512];

Input = fopen ("File.in", "R B");

Output = fopen ("File.out", "W");

/ * SET UP INPUT Stream for Minimal Disk Access,

USING OUR OWN Character Buffer * /

IF (setvbuf (Input, bufr, _iofbf, 512)! = 0)

Printf ("Failed to Set Up Buffer For Input File / N");

Else

Printf ("Buffer Set Up for Input File / N);

/ * SET UP OUTPUT STREAM for Line Buffering Using Space Thatwill Be Obtained THROUGH AN Indirect Call To Malloc * /

IF (setput, null, _iolbf, 132)! = 0)

Printf ("Failed to Set Up Buffer for Output File / N");

Else

Printf ("Buffer Set Up for Output File / N);

/ * Perform file I / o here * /

/ * Close Files * /

Fclose (INPUT);

Fclose (OUTPUT);

Return 0;

}

Function name: setVect

Function: Setting the interrupt vector entrance

Usage: void setvect (int INTR_NUM, VOID INTERRUPT (* ISR) ());

Example:

/ *** Note:

This is an interrupt service routine. You can not compile h

Program with test stack overflow turned on and get an executable

File Which Will Operate Correctly. * /

#include

#include

#include

#define INTR 0x1C / * The Clock Tick Interrupt * /

Void Interrupt (* OldHandler) (Void);

INT count = 0;

Void Interrupt Handler (Void)

{

/ * Increase the global counter * /

COUNT ;

/ * Call the Old Routine * /

OldHandler ();

}

Int main (void)

{

/ * Save the old interrupt vector * /

OldHandler = GetVect (INTR);

/ * Install the new interface 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;

}

Function name: setverify

Function: Set the verification status

Usage: void setver (int value);

Example:

#include

#include

#include

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;

}

Function name: setViewPort

Function: Set the current viewport for the graphic output

Usage: Void Far SetViewPort (int LEFT, INT TOP, INT RIGHT,

INT bottom, int clipflag;

Example:

#include

#include

#include

#include

#define clip_on 1 / * Activates Clipping in ViewPort * /

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

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

}

SetColor (GetMaxColor ());

/ * Message in default full-screen viewport * /

Outtextxy (0, 0, "* <- (0, 0) in Default ViewPort");

/ * CREATE A SMALLER ViewPort * /

SetViewPort (50, 50, getmaxx () - 50, getmaxy () - 50, clip_on;

/ * Display Some Text * /

Outtextxy (0, 0, "* <- (0, 0) in smaller viewport");

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setvisualpage

Function: Setting the visible graphics page number

Usage: Void Far setvisualPage (int Pagenum);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * SELECT A Driver and Mode That Supports * /

/ * MULTIPLE PAGES. * /

INT GDRIVER = EGA, GMODE = Egahi, ErrorCode;

INT X, Y, HT;

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

}

x = getmaxx () / 2;

y = getmaxy () / 2;

HT = Textheight ("W");

/ * SELECT The Off Screen Page for Drawing * /

SetActivePage (1);

/ * Draw a line on page # 1 * /

Line (0, 0, getmaxx (), getmaxy ());

/ * Output a message on page # 1 * /

SetTextJustify (center_text, center_text);

Outtextxy (x, y, "this is page # 1:");

Outtextxy (x, y ht, "press any key to halt:");

/ * SELECT DRAWING to Page # 0 * /

SetActivePage (0);

/ * OUTPUT A Message on Page # 0 * /

OutTextxy (x, y, "this is page # 0.");

Outtextxy (x, y HT, "Press Any Key to View Page # 1:");

Getch ();

/ * SELECT Page # 1 as the visible page * /

SetvisualPage (1);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setwritemode

Features: Set the output mode of the drawing line of the graphics mode

Usage: Void Far Setwritemode (int M);

Example:

#include

#include

#include

#include

int main ()

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT XMAX, YMAX;

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

}

XMAX = getmaxx ();

YMAX = getMaxy ();

/ * SELECT XOR DRAWING MODE * /

Setwritemode (XOR_PUT);

/ * Draw a line * / line (0, 0, xmax, ymax);

Getch ();

/ * Erase the line by Drawing over it * /

LINE (0, 0, Xmax, Ymax);

Getch ();

/ * SELECT OVERWRITE DRAWING MODE * /

Setwritemode (COPY_PUT);

/ * Draw a line * /

LINE (0, 0, Xmax, Ymax);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: Signal

Function: Set the corresponding action of a signal

Usage: int Signal (int Sig, Sigfun FNAME);

Example:

/ * This Example Installs A Signal Handler Routine for SIGFPE,

Catches an integer overflow condition, makes an adjustment

TO AX Register, And Returns. This Example Program May Cause

Your Computer To Crash, And Will Produce Runtime ErrorS

Depending on Which Memory Model is used.

* /

#pragma inline

#include

#include

Void Catcher (int Sig, int Type, int * reglist)

{

Printf ("caught it! / n");

* (Reglist 8) = 3; / * make returna = 3 * /

}

Int main (void)

{

Signal (SIGFPE, CATCHER);

ASM MOV AX, 07FFFH / * AX = 32767 * /

ASM INC AX / * Cause overflow * /

ASM INTO / * ACTIVATE HANDLER * /

/ * The Handler Set Ax To 3 on Return. If That Hadn't Happened,

There Would Have Been Another Exception When the next 'inTo'

WAS EXECUTED AFTER THE 'DEC' INSTRUCTION. * /

ASM DEC AX / * No Overflow Now * /

ASM INTO / * DOESN'T ACTIVATE * /

Return 0;

}

Function name: sin

Function: sinusoidal function

Usage: Double Sin (double x);

Example:

#include

#include

Int main (void)

{

Double Result, x = 0.5;

Result = sin (x);

Printf ("The sin () of% LF IS% LF / N", X, Result);

Return 0;

}

Function name: sinh

Function: Double Sinusoidal Function

Usage: Double Sinh (Double X);

Example:

#include

#include int main (void)

{

Double Result, x = 0.5;

Result = sinh (x);

Printf ("" The HyperBolic sin () OF% LF IS% LF / N ", X, Result);

Return 0;

}

Function name: SLEEP

Dynamic: Perform a pending period

Usage: Unsigned Sleep (unsigned seconds);

Example:

#include

#include

Int main (void)

{

INT I;

For (i = 1; i <5; i )

{

Printf ("Sleeping for% D Seconds / N", i);

Sleep (i);

}

Return 0;

}

Function name: Sopen

Function: Open a share of the file

Usage: int sithname, int access, int shflag, int permiss;

Example:

#include

#include

#include

#include

#include

#include

Int main (void)

{

INT HANDLE;

Int status;

Handle = Sopen ("c: //autoexec.bat", o_rdonly, sh_denyno, s_iread);

IF (! Handle)

{

Printf ("Sopen Failed / N");

Exit (1);

}

Status = Access ("c: //autoexec.bat", 6);

IF (status == 0)

Printf ("Read / Write Access ALLOWED / N);

Else

Printf ("Read / Write Access Not ALOWED / N);

Close (Handle);

Return 0;

}

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

New Post(0)