C language library function (S type letters) - 1

xiaoxiao2021-03-06  41

Function name: SBRK

Function: Change the location of the data segment

Usage: char * sbrk (int INCR);

Example:

#include

#include

Int main (void)

{

Printf ("Changing Allocation with SBRK () / N");

Printf ("Before Sbrk () Call:% Lu Bytes Free / N",

(unsigned long) Coreleft ());

SBRK (1000);

Printf ("After Sbrk () Call:% Lu Bytes Free / N",

(unsigned long) Coreleft ());

Return 0;

}

Function name: scanf

Function: Implementation formatting

Usage: int Scanf (char * format [, argument, ...]);

Example:

#include

#include

Int main (void)

{

Char label [20];

Char Name [20];

INT entries = 0;

Int loop, agn;

Double Salry;

Struct Entry_Struct

{

Char Name [20];

Int agec;

Float Salry;

Entry [20];

/ * Input a label as a string of characters restricting to 20 characters * /

Printf ("/ N / N / NPLEASE ENTER A Label for the Chart:");

Scanf ("% 20s", Label;

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input Number of Entries as an inTeger * /

Printf ("How Many Entries Will there be? (Less Than 20)");

Scanf ("% d", & entries);

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input a name restricting input to only letters upper or limited number * /

For (loop = 0; loop

{

Printf ("Entry% D / N", LOOP;

Printf ("Name:");

Scanf ("% [A-ZA-Z]", Entry [loop] .name;

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input an agent AGE as an integer * /

Printf ("Age:");

Scanf ("% D", & Entry [loop] .age);

Fflush (stdin); / * flush the input stream in case of bad input * /

/ * Input a Salary as a float * /

Printf ("Salary:");

Scanf ("% f", & entry [loop] .salary); fflush (stdin); / * Flush the Input stream in case of bad input * /

}

/ * Input a name, Age and Salary as a string, integer, and double * /

Printf ("/ NPLEASE ENTER Your Name, Age and Salary / N");

Scanf ("% 20S% D% LF", Name, & Age, & Salary;

/ * Print Out the Data That Was Input * /

Printf ("/ N / NTABLE% S / N", Label);

Printf ("Compiled BY% S AGE% D $% 15.2LF / N", Name, AGE, SALARY);

Printf ("--------------------------------------------- ------ / n ");

For (loop = 0; loop

Printf ("% 4D |% -20S |% 5D |% 15.2LF / N",

LOOP 1,

Entry [loop] .name,

Entry [loop] .age,

Entry [loop] .salary;

Printf ("--------------------------------------------- ------ / n ");

Return 0;

}

Function Name: SearchPath

Function: Search DOS path

Usage: char * searchpath (char * filename);

Example:

#include

#include

Int main (void)

{

Char * p;

/ * Looks for TLINK AND RETURNS A POINTER

To the Path * /

P = SearchPath ("TLINK.exe");

Printf ("Search for TLink.exe:% S / N", P);

/ * Looks for non-eviStent file * /

P = SearchPath ("NOTEXIST.FIL");

Printf ("Search for Notexist.fil:% S / N", P);

Return 0;

}

Function Name: SECTOR

Function: Draw and populate the elliptical sector

Usage: Void Far Sector (int X, int y, int standle, int endangle);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int midx, midy, i;

INT Stangle = 45, endangle = 135;

INT XRAD = 100, YRAD = 50;

/ * Initialize Graphics and Local Variables * /

INITGRAPH (& gdriver, & gmode, "); / * read result of infitization * /

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 = EMPTY_FILL; I

{

/ * SET the FILL STYLE * /

SetFillStyle (i, getmaxcolor ());

/ * DRAW the SECTOR SLICE * /

Sector (MIDX, Midy, Stangle, Endangle, XRAD, YRAD);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: segread

Function: Read Section Register Value

Usage: void segread (struct Sregs * segtbl);

Example:

#include

#include

Int main (void)

{

Struct Sregs Segs;

Segread (& segs);

Printf ("Current Segment Register Settings / N / N");

Printf ("CS:% x DS:% x / n", segs.cs, segs.ds;

Printf ("ES:% X SS:% x / n", segs.es, segs.ss;

Return 0;

}

Function Name: SetActivePage

Finance: Set the graphic output activity page

Usage: Void Far SetActivePage (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: setAllPallette

Function: Change all palette colors by specified mode

Usage: Void Far SetallPallette (Struct Palette, Far * Pallette);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Struct PaletType Pal;

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");

/ * GRAB a COPY OF THE PALETTE * /

GetPalette (& PAL);

/ * DISPLAY THE DEFAULT PALETTE 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 ();

}

/ * RESTORE THE PALETTE Colors * /

SetAllPalette (& PAL);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: SetAspectratio

Function: set the graphical crossing ratio

Usage: Void Far Setaspectratio (int XASP, INT YASP);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT XASP, YASP, MIDX, MIDY;

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

SetColor (GetMaxColor ());

/ * Get Current Aspect Ratio Settings * /

Getaspectratio (& XASP, & YASP);

/ * DRAW NORMAL CIRCLE * /

Circle (MIDX, MIDY, 100);

Getch ();

/ * Claer the screen * /

ClearDevice ();

/ * Adjust the aspect for a wide circle * /

Setaspectratio (XASP / 2, YASP);

Circle (MIDX, MIDY, 100);

Getch ();

/ * Adjust the assect for a narrow circle * /

ClearDevice ();

Setaspectratio (XASP, YASP / 2);

Circle (MIDX, MIDY, 100);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;}

Function name: setbkcolor

Function: Set the current background color with a palette

Usage: Void Far SetBkcolor (int color);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * SELECT A Driver and Mode That Supports * /

/ * Multiple Background Colors. * /

INT GDRIVER = EGA, GMODE = Egahi, ErrorCode;

INT BKCOL, MAXCOLOR, X, Y;

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

}

/ * Maximum color index supported * /

MaxColor = getMaxcolor ();

/ * For centering text messages * /

SetTextJustify (center_text, center_text);

x = getmaxx () / 2;

y = getmaxy () / 2;

/ * Loop through the available colors * /

For (BKCOL = 0; BKCOL <= MaxColor; BKCOL )

{

/ * Clear the screen * /

ClearDevice ();

/ * SELECT A New Background Color * /

SetBkcolor (BKCOL);

/ * OUTPUT A MESSSAGE * /

IF (bkcol == white)

SetColor (EGA_BLUE);

Sprintf (MSG, "Background Color:% D", BKCOL);

OutTextxy (X, Y, MSG);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: setblock

Function: Modify the size of the previously allocated DOS storage segment

Usage: int setBlock (int SEG, INT newsize);

Example:

#include

#include

#include

#include

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% D / N",

STAT);

Exit (1);

}

Stat = setblock (segp, size * 2);

IF (stat == -1)

Printf ("Expanded Memory Block At Segment:% x / n", segp);

Else

Printf ("Failed: Maximum Number Of Paragraphs Available IS% D / N",

STAT);

FreeMem (segp);

Return 0;

}

Function name: setbuf

Function: Associate the buffer with flow

Usage: Void SetBuf (File * Steam, Char * BUF);

Example:

#include

/ * Bufsiz is defined in stdio.h * /

Char outbuf [bufsiz];

Int main (void)

{

/ * Attach a buffer to the standard output stream * /

SetBUF (stdout, outbuf);

/ * Put Some Characters INTO The Buffer * /

PUTS ("This Is A Test of Buffered Output./N");

PUTS ("This Output Will Go Into Outbuf / N");

PUTS ("And Won't Appear Until The Buffer / N);

PUTS ("Fills Up or We Flush The Stream./N");

/ * Flush the output buffer * /

Fflush (stdout);

Return 0;

}

Function name: setcbrk

Function: Set Control-Break

Usage: int setcbrk (int value);

Example:

#include

#include

#include

Int main (void)

{

INT BREAK_FLAG;

Printf ("Enter 0 to Turn Control Break Off / N");

Printf ("Enter 1 To Turn Control Break ON / N);

Break_flag = getCH () - 0;

SetcBrk (Break_flag);

IF (getcbrk ())

Printf ("CNTRL-BRK FLAG IS ON / N");

Else

Printf ("CNTRL-BRK FLAG IS OFF / N");

Return 0;

}

Function name: setColor

Function: Set the current line color

Usage: Void Far SetColor (int color);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * SELECT A Driver and Mode That Supports * /

/ * MULTIPLE DRAWING Colors. * / INT GDRIVER = EGA, GMODE = Egahi, ErrorCode;

Int Color, MaxColor, X, Y;

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

}

/ * Maximum color index supported * /

MaxColor = getMaxcolor ();

/ * For centering text messages * /

SetTextJustify (center_text, center_text);

x = getmaxx () / 2;

y = getmaxy () / 2;

/ * Loop through the available colors * /

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

{

/ * Clear the screen * /

ClearDevice ();

/ * SELECT A New Background Color * /

SetColor (Color);

/ * OUTPUT A MESSSAGE * /

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

OutTextxy (X, Y, MSG);

Getch ();

}

/ * Clean Up * /

Closegraph ();

Return 0;

}

Function name: setdate

Finance: Set DOS Date

Usage: void setdate (struct date * dateblk);

Example:

#include

#include

#include

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;

}

Function name: setDisk

Function: Set the current disk drive

Usage: int setDisk (int drive);

Example:

#include

#include int main (void)

{

Int Save, Disk, Disks;

/ * Save Original Drive * /

Save = getDisk ();

/ * Print Number of Logic Drives * /

Disks = setDisk (save);

Printf ("% D Logical Drives On The System / N / N", Disks);

/ * Print The Drive Letters Available * /

Printf ("Available Drives: / N");

For (Disk = 0; Disk <26; DISK)

{

SetDisk (Disk);

IF (Disk == getDisk ())

Printf ("% C: Drive is Available / N", Disk 'A');

}

SetDisk (Save);

Return 0;

}

Function name: setdta

Features: Set the disk transfer area address

Usage: Void Setdta (Char Far * DTA);

Example:

#include

#include

#include

#include

Int main (void)

{

CHAR LINE [80], FAR * SAVE_DTA;

CHAR BUFFER [256] = "setdta test!";

Struct FCB BLK;

Int result;

/ * Get new file name from user * /

Printf ("Enter A File Name to Create:");

Gets (line);

/ * Parse the new file name to the dta * /

PARSFNM (Line, & BLK, 1);

Printf ("% D% S / N", BLK.FCB_DRIVE, BLK.FCB_NAME);

/ * Request dos Services to create file * /

IF (BDoSPTR (0x16, & BLK, 0) == -1)

{

"" "ERROR CREANG FILE");

Exit (1);

}

/ * Save Old DTA and SET New DTA * /

Save_dta = getdta ();

Setda (buffer);

/ * Write new records * /

BLK.FCB_RECSIZE = 256;

BLK.FCB_Random = 0L;

Result = RANDBWR (& BLK, 1);

Printf ("Result =% D / N", Result;

IF (! result)

Printf ("Write OK / N");

Else

{

PERROR ("Disk Error");

Exit (1);

}

/ * Request DOS Services to Close THE FILE * /

IF (BDOSPTR (0x10, & BLK, 0) == -1)

{

"" ERROR Closing File ");

Exit (1);

}

/ * RESET the OLD DTA * /

SetDA (Save_DTA);

Return 0;

}

Function Name: SetFillPatterN function: Select user-defined fill mode

Usage: Void Far setfillPattern (Char Far * Upattern, Int Color);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

Int Maxx, Maxy;

/ * A user defined film Pattern * /

Char pattern [8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00};

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

MAXY = getMaxy ();

SetColor (GetMaxColor ());

/ * SELECT A User Defined Fill Pattern * /

SetFillPattern (Pattern, getmaxcolor ());

/ * Fill the screen with the pattern * /

BAR (0, 0, Maxx, Maxy);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setfillstyle

Function: Set the padding mode and color

Usage: Void Far SetFillStyle (int pattern, int color);

Example:

#include

#include

#include

#include

#include

/ * The names of the weight styles supported * /

Char * fname [] = {"EMPTY_FILL",

"Solid_Fill",

"LINE_FILL",

"LTSLASH_FILL",

"Slash_Fill",

"BKSLASH_FILL",

"LTBKSLASH_FILL",

"Hatch_fill",

"Xhatch_fill",

"Interleave_fill",

"WIDE_DOT_FILL",

"Close_dot_fill",

"User_fill"

}

Int main (void)

{

/ * Request Auto Detection * / INT GDRIVER = Detect, Gmode, ErrorCode

Int Style, MIDX, Midy;

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;

For (Style = Empty_Fill; Style

{

/ * SELECT the FILL STYLE * /

SetFillStyle (Style, getmaxcolor ());

/ * Convert Style Into A String * /

STRCPY (Stylestr, FName [style]);

/ * Fill a bar * /

BAR3D (0, 0, MIDX-10, MIDY, 0, 0);

/ * OUTPUT A Message * /

OutTextxy (MIDX, Midy, StyleStr);

/ * Wait for a key * /

Getch ();

ClearDevice ();

}

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setftime

Finance: set file date and time

Usage: int setftime (int Handle, Struct ftime * ftimep);

Example:

#include

#include

#include

#include

Int main (void)

{

Struct ftime file;

File * fp;

IF ((fp = fopen ("Test. $$$", "w")) == NULL)

{

PERROR ("Error:");

Exit (1);

}

FPRINTF (FP, "Testing ... / N");

/ * Load ftime structure with new time and date * /

Filet.ft_tsec = 1;

FILET.FT_MIN = 1;

Filet.ft_Hour = 1;

Filet.ft_day = 1;

FILET.FT_MONTH = 1;

FILET.FT_YEAR = 21;

/ * Show Current Directory for Time and Date * /

System ("Dir Test. $$$");

/ * Change the time and date stamp * /

SetFTIME (Fileno (FP), & Filet);

/ * Close And Remove The Temporary File * / Fclose (FP);

System ("Dir Test. $$$");

Unlink ("Test. $$$");

Return 0;

}

Function name: setgraphbufsize

Function: Change the size of the internal graphics buffer

Usage: UNSIGNED FAR setgraphbufsize (unsigned buffsize);

Example:

#include

#include

#include

#include

#define bufsize 1000 / * Internal Graphics Buffer Size * /

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT X, Y, Oldsize;

Char msg [80];

/ * SET the size of the interfacel graphics buffer * /

/ * Before Making a call to initgraph. * /

Oldsize = setgraphbufsize (bufsize);

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

/ * OUTPUT SOME Messages * /

Sprintf (MSG, "Graphics Buffer Size:% D", BUFSIZE

SetTextJustify (center_text, center_text);

OutTextxy (X, Y, MSG);

Sprintf (MSG, "Old Graphics Buffer Size:% D", OldSize);

Outtextxy (x, y textheight ("w"), MSG);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: setgraphmode

Function: set the system into graphics mode and clear screen

Usage: Void Far setgraphmode (int M);

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

INT X, Y;

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

/ * OUTPUT A Message * /

SetTextJustify (center_text, center_text);

Outtextxy (X, Y, "Press Any Key to EXIT Graphics:");

Getch ();

/ * RESTORE SYSTEM to TEXT MODE * /

RestoreCRTMode ();

Printf ("We're now in text mode./n);

Printf ("Press Any Key to Return to Graphics Mode:");

Getch ();

/ * Return to graphics mode * /

Setgraphmode (GETGRAPHMODE ());

/ * OUTPUT A Message * /

SetTextJustify (center_text, center_text);

OutTextxy (X, Y, "We're Back in graphics mode.");

Outtextxy (x, y textheight ("w"), "Press any key to halt:");

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

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

New Post(0)