C function library Daquan 1

xiaoxiao2021-03-06  54

Function Name: WHEREX Features: Return to Horizontal Cursor Location Usage: INT WHEREX (VOID);

#include

INT main (void) {clrs CL (); gotoxy (10, 10); CPRINTF ("Current Location IS X:% D Y:% D / R / N", wherex (), wherey ()); getch ();

Return 0;}

Function Name: WHEREY Energy: Return to Vertical Castronics Location Usage in Window: Int WhereY (Void);

#include

INT main (void) {clrs CL (); gotoxy (10, 10); CPRINTF ("Current Location IS X:% D Y:% D / R / N", wherex (), wherey ()); getch ();

Return 0;}

Function Name: Window Features: Defining Activity Text Mode Window Usage: Void WINDOW (int LEFT, INT TOP, INT RIGHT, INT BOTTOM);

#include

INT main (void) {

WINDOW (10, 10, 40, 11); TextColor (Black); TextBackground (White); CPrintf ("this is a test / r / n");

Return 0;}

Function Name: Write Features: Writing a File Usage: int Write (int Handel, Void * BUF, INT NBYTE);

#include

#include

#include

#include

#include

#include

INT main (void) {int Handle; Char string [40]; int LENGTH, RES;

/ * CREATE A File Named "TEST. $$$" in The Current Directory and Write A String To It. If "Test. $$$" Already Exists, IT Will Be overwritten. * /

IF (("Test. $$$", O_Wronly | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)) == -1) {Printf ("Error Opening File./N"); exit (1);}

STRCPY (String, "Hello, World! / N"); Length = Strlen (String);

IF ((res = Write (Handle, String, Length))! = length) {Printf ("Error Writing to the file./N); exit (1);} Printf (" Wrote% D bytes to the file. / N ", RES);

Close (Handle); Return 0;

Struct xfcb {

Char XFCB_FLAG; / * Contains 0xFf to INDICATE XFCB * /

Char XFCB_RESV [5]; / * Reserved for dos * /

Char XFCB_ATTR; / * Search Attribute * /

Struct FCB XFCB_FCB; / * The Standard FCB * /

}

Function name: Vfprintf function: send formatted output to first-class usage: int vfprintf (file * stream, char * format, va_list param); program case: #include

#include

#include

File * fp;

INT VFPF (Char * fmt, ...) {va_list argptr; int CNT;

VA_Start (Argptr, FMT); CNT = Vfprintf (FP, FMT, Argptr); VA_END (ARGPTR);

Return (CNT);

INT main (void) {INUMBER = 30; float fnumber = 90.0; char string [4] = "abc";

FP = tmpfile (); if (fp == null) {PERROR ("tmpfile () call"; exit (1);}

VFPF ("% D% F% S", Inumber, FNumber, String; ReWind (fp); FSCANF (FP, "% D% F% S", & Inumber, & fnumber, string); Printf ("% D% F % S / N ", Inumber, Fnumber, String; Fclose (FP);

Return 0;}

Function name: VFSCANF function: Perform formatting input from flow: int vfscanf (file * stream, char * format, va_list param);

#include

#include

#include

File * fp;

INT VFSF (CHAR * FMT, ...) {VA_List Argptr; int CNT;

VA_START (Argptr, FMT); CNT = VFSCANF (FP, FMT, Argptr); VA_END (Argptr);

Return (CNT);

INT main (void) {INUMBER = 30; float fnumber = 90.0; char string [4] = "abc";

FP = TMPFILE (); if (fp == null) {Perror ("TmpFile () call"; exit (1);} fprintf (fp, "% D% f% S / N", Inumber, Fnumber, String ReWind (fp);

VFSF ("% D% F% S", & Inumber, & FNumber, String); Printf ("% D% F% S / N", Inumber, Fnumber, String; Fclose (FP);

Return 0;}

Function Name: Vprintf Features: Send Format Output to Stdout Usage: Int Vprintf (Char * Format, VA_List Param);

#include

#include

INT VPF (Char * fmt, ...) {va_list argptr; int CNT;

VA_Start (argptr, format); cnt = vprintf (fmt, argptr); VA_END (Argptr);

Return (CNT);

INT main (void) {INUMBER = 30; float fnumber = 90.0; char * string = "abc";

VPF ("% D% F% S / N", Inumber, Fnumber, String; Return 0;}

Function name: vscanf function: Format input from stdin: int vscanf (char * format, va_list param);

#include

#include

#include

INT VSCNF (Char * fmt, ...) {va_list argptr; int CNT;

Printf ("Enter an INTEGER, A Float, And A String (E.G. I, F, S,) / N"); VA_START (Argptr, FMT); CNT = VSCANF (FMT, Argptr); VA_END (Argptr);

Return (CNT);

INT main (void) {int inumber; float fnumber; char string [80];

VSCNF ("% D,% F,% s", & inumber, & fnumber, string; printf ("% D% f% s / n", inumber, fnumber, string;

Return 0;}

Function Name: VSPrintf function: send formatted output to string: int vsprintf (char * string, char * format, va_list param); program case:

#include

#include

#include

Char buffer [80];

INT VSPF (Char * fmt, ...) {va_list argptr; int CNT;

VA_Start (Argptr, FMT); CNT = vSprintf (Buffer, FMT, Argptr); VA_END (Argptr);

Return (CNT);

INT main (void) {INUMBER = 30; float fnumber = 90.0; char string [4] = "abc";

VSPF ("% D% F% S", Inumber, FNumber, String); Printf ("% s / n", buffer; return 0;}

Function Name: Vsscanf Features: Performs Format Input from the stream: int Vsscanf (Char * S, Char * Format, VA_LIST PARAM);

#include

#include

#include

Char buffer [80] = "30 90.0 ABC";

INT VSSF (Char * fmt, ...) {va_list argptr; int CNT;

Fflush (stdin);

VA_START (Argptr, FMT); CNT = Vsscanf (Buffer, FMT, Argptr); VA_END (Argptr);

Return (CNT);

INT main (void) {int inumber; float fnumber; char string [80];

VSSF ("% D% F% S", & Inumber, & FNumber, String); Printf ("% D% F% S / N", Inumber, Fnumber, String; Return 0;}

Function Name: UltoA function: Convert an unsigned long integer as a string usage: char * Ultoa (unsigned long value, char * string, int RADIX);

#include

#include

INT main (void) {unsigned long lnumber = 3123456789l; char string [25]; Ultoa (lnumber, string, 10); printf ("string =% s unsigned long =% lu / n", string, lnumber;

Return 0;}

Function Name: UNGETC function: Return a character to the input stream: int ungetc (Char C, File * Stream);

#include

#include

INT main (void) {INT i = 0; char CH;

PUTS ("INPUT AN INTEGER FOLLOWED BY A CHAR:");

/ * Read Chars Until Non Digit or EOF * / while ((ch = getchar ())! = EOF && Isdigit (CH)) i = 10 * i ch - 48; / * Convert Ascii Into Int value * /

/ * if Non Digit Char Was Read, Push IT Back Into Input Buffer * / if (CH! = EOF) Ungetc (CH, STDIN);

Printf ("I =% D, Next Char in buffer =% C / N", I, getchar ()); return 0;}

Function Name: Ungetch Fenergy: Return a character to the keyboard buffer: int ungetch (INT C);

#include

#include

#include

INT main (void) {INT i = 0; char CH;

PUTS ("INPUT AN INTEGER FOLLOWED BY A CHAR:");

/ * Read Chars Until Non Digit or EOF * / WHILE ((CH = getche ())! = EOF && Isdigit (CH)) i = 10 * i ch - 48; / * Convert Asci Into int value * /

/ * if Non Digit Char Was Read, Push IT Back INTO INPUT BUFFER * / IF (CH! = EOF) Ungetch (CH);

Printf ("/ n / ni =% D, Next Char in buffer =% C / N", I, getCH ()); return 0;}

Function Name: UnixTodos Features: Convert date and Time to DOS Format: Void UnixTodos (Long Utime, Struct Date * DatePtr, Struct Time * TimePtr);

#include

#include

Char * MONTH [] = {"---", "Jan", "Feb", "Mar", "APR", "May", "Jun", "Jul", "AUG", "SEP", " Oct "," NOV "," DEC "};

#define seconds_per_day 86400l / * the number of seconds in one day * /

Struct date dt; struct time TM;

INT main (void) {unsigned long Val

/ * GET TODAY's DATE AND TIME * / GETDATE (& DT); GetTime (& TM); Printf ("Today IS% D% S% D / N", DT.DA_DAY, MONTH [DT.DA_MON], DT.DA_YEAR);

/ * Convert Date and Time to Unix Format (Number of Seconds Since Jan 1, 1970 * / Val = Dostounix (& DT, & TM); / * Subtract 42 Days Worth of Seconds * / Val - = (Seconds_Per_Day * 42);

/ * Convert Back to DOS TIME AND DATE * / UnixTodos (VAL, & DT, & TM); Printf ("42 Days AGO IT WAS% D% S% D / N", DT.DA_DAY, MONTH [DT.DA_MON], DT .da_year); return 0;}

Function Name: Unlink Features: Delete a File Usage: Int Unlink (Char * filename);

#include

#include

INT main (void) {file * fp = fopen ("junk.jnk", "w"); int stat;

FPRINTF (FP, "JUNK");

STATUS = Access ("Junk.jnk", 0); if (status == 0) Printf ("File EXISTS / N"); Else Printf ("File Doesn't Exist / N);

Fclose (fp); unlink ("junk.jnk"); status = access ("junk.jnk", 0); if (status == 0) Printf ("File EXISTS / N"); Else Printf ("File Doesn 'T EXIST / N ");

Return 0;}

Function Name: UNLOCK Features: Release File Sharing Lock: Int Unlock (Int Handle, Long Offset, Long Length);

#include

#include

#include

#include

#include

#include

Int main (void) {Int Handle, Status; Long Length;

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

IF (Handle <0) {Printf ("Sopen Failed / N"); exit (1);}

Length = fileLength (Handle); Status = LOCK (Handle, 0L, Length / 2);

IF (status == 0) Printf ("Lock succeeded / n"); Else Printf ("Lock Failed / N");

Status = UNLOCK (Handle, 0L, Length / 2);

IF (status == 0) Printf ("unlock succeeded / n"); Else Printf ("Unlock Failed / N"); Close (Handle); Return 0;}

Function Name: TAN Fenergy: Positive Split Function Usage: Double Tan (Double X); Procedure:

#include

#include

INT main (void) {Double Result, X;

x = 0.5; Result = TAN (X); Printf ("Tan Of% LF IS% LF / N", X, Result); Return 0;}

Function Name: TanH Function: Double Division Positive Split Function: Double Tanh (Double X);

#include

#include

INT main (void) {Double Result, X;

x = 0.5; Result = tanh (x); Printf ("The HyperBolic Tangent Of% LF IS% LF / N", X, Result; Return 0;}

Function name: TELL function: Take the current location of the file pointer: long tell (int Handle);

#include

#include

#include

#include

INT main (void) {Int Handle; char msg [] = "Hello World";

IF (("Test. $$$", O_Creat | O_Text | O_APpend)) == -1) {Perror ("Error:"); Return 1;} Write (Handle, MSG, Strlen (MSG) PRINTF ("The File Pointer IS AT BYTE% LD / N", Tell (Handle); Close (Handle); Return 0;}

Function Name: TextAtTR Function: Settings Text Attribute Usage: Void Textattr (INT Attribute);

#include

INT main (void) {INT I;

CLRSCR (); for (i = 0; i <9; i ) {textattr (i ((i 1) << 4)); CPRINTF ("this is a test / r / n");}

Return 0;}

Function Name: Textbackground Features: Select New Text Background Color Usage: Void TextBackground (INT Color);

#include

INT main (void) {INT I, J;

CLRSCR (); for (i = 0; i <9; i ) {for (j = 0; j <80; j ) CPrintf ("c"); CPrintf ("/ r / n"); TextColor (i 1); TextBackground (i);

Return 0;}

Function Name: TextColor Features: Select New Character Color Usage in Text Mode: Void TextColor (int color); program case: #include

INT main (void) {INT I;

For (i = 0; i <15; i ) {textcolor (i); CPRINTF ("Foreground COLOR / R / N");}

Return 0;} function name: TextHeight function: Returns a string height usage in pixels: int Far TextHeight (Char Far * TextString);

#include

#include

#include

#include

INT main (void) {/ * request auto detection * / int gDriver = detect, gmode, errorcode; int y = 0; int i; char msg [80];

/ * Initialize Graphics and local variables * / initgraph (& gdriver, & gmode, "");

/ * read results = graphresult (); if (error (error) / * an error opcurred * / {printf ("Graphics Error:% S / N", GrapherrorMSG (ErrorCode)); Printf (" Press any key to halt: "); getCH (); exit (1); / * Terminate with an error code * /}

/ * Draw Some text on the screen * / for (i = 1; i <11; i ) {/ * select the text style, direction, and size * / settextStyle (Triplex_Font, Horiz_Dir, i);

/ * CREATE A Message String * / Sprintf (MSG, "Size:% D", i);

/ * Output the message * / Outtextxy (1, y, msg);

/ * Advance to the next text line * / y = textHeight (msg);

/ * CLOAN UP * / GETCH (); closegraph (); return 0;}

Function Name: TextMode Fence: Set the screen into a text mode: void textmode (int mode);

#include

INT main (void) {TextMode (BW40); CPRINTF ("abc"); getch ();

TextMode (C40); CPRINTF ("ABC"); getch ();

TextMode (BW80); CPRINTF ("ABC"); getCH ();

TextMode (C80); CPRINTF ("ABC"); getch ();

TextMode (Mono); CPrintf ("abc"); getch ();

Return 0;}

Function Name: TextWidth Features: Returns a string width usage with pixels: int Far TextWidth (Char Far * TextString);

#include

#include

#include

#include

INT main (void) {/ * request auto detection * / int gDriver = detect, gmode, errorcode; int x = 0, y = 0; int I; char msg [80];

/ * 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", GraphherrorMSG (ErrorCode)); Printf ("Press Any Key to Halt:"); getCh (); exit (1); / * Terminate with an error code * /}

y = getmaxy () / 2;

SetTextJustify (Left_Text, Center_text); for (i = 1; i <11; i ) {/ * select the text style, direction, and size * / settextStyle (Triplex_Font, Horiz_Dir, i);

/ * CREATE A Message String * / Sprintf (MSG, "Size:% D", i);

/ * Output The Message * / OutTextxy (X, Y, MSG);

/ * Advance to the end of the text * / x = textwidth (msg);

/ * CLOAN UP * / GETCH (); closegraph (); return 0;}

Function Name: TIME Function: Take a day of time: logn Time (long * tloc);

#include

#include

#include

INT main (void) {TIME_T T;

T = Time (NULL); Printf ("The Number of Seconds Since January, 1970 IS% LD", T); Return 0;}

Function name: TMPFile function: Temption file usage in binary: file * tmpfile (void);

#include

#include

INT main (void) {file * Tempfp;

Tempfp = tmpfile (); if (tempfp) Printf ("Temporary File Created / N"); Else {Printf ("Unable to Create Temporary File / N); Exit (1);

Return 0;}

Function Name: TMPNAM Features: Create a unique file name method: char * tmpnam (char * sptr); program case:

#include

INT main (void) {char name [13];

TMPNAM (Name); Printf ("Temporary Name:% S / N", Name); Return 0;}

Function Name: TOLOWER function: Convert characters into lowercase letters: int TOLOWER (INT C);

#include

#include

#include

INT main (void) {Int Length, i; char * string = "this is a string";

Length = strlen (string); for (i = 0; i

{

String [i] = tolower (String [i]);

}

Printf ("% s / n", string); return 0;}

Function name: TouPper function: Convert character to uppercase letters: int Toupper (INT C);

#include

#include

#include

INT main (void) {Int Length, i; char * string = "this is a string";

Length = strlen (string); for (i = 0; i

{

String [I] = Toupper (String [i]);

}

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

Return 0;}

Function Name: TZSET Function: UNIX Time Compatible Function Usage: Void Tzset (VOID);

#include

#include

#include

INT main (void) {TIME_T TD;

Putenv ("TZ = PST8PDT"); tzset (); Time (& TD); Printf ("Current Time =% S / N", Asctime (LocalTime (& TD))); return 0;}

Function Name: SetTime Features: Set System Time Law: Void SetTime (Struct Time * Timep); Procedure: #include

#include

INT main (void) {struct time t; gettime (& t); Printf ("THE Current Minute IS:% D / N", T.Ti_MIN); Printf ("The 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 struct element and life call settime * / t.ti_min ; settime (& t); Return 0;} function name: setusercharsize function: change character width and height for vector font: Void Far Setusercharsize (int Multx, Int Dirx, int Multy , int diry; program: #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 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 * /} / * selecttexTyle (Triplex_Font, Horiz_Dir, 4); / * Move To the text Starting Position * / Moveto (0, getMax () / 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: related buffer with streams: 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 that will be obtained through an indirect call to malloc * / if (setvbuf (output, 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);} function name: setVect function: Setting interrupt vector entry usage: void setVect (int ISR) ()); program: / ** * Note: this is an interrupt service routine. You can not compile this program with test stack overflow turned on and get an executable file Which will operate correctly. * / # Incrude # 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 interrupt handler * / setvect (inter, handler); / * loop unsteil the Counter Exceeds 20 * / while (count <20) Printf ("Count IS% D / N", count); / * reset the old interrupt handler * / setvect (internal); return 0;} function name: setverify function : Set the verification status usage: void setVerify; 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: Setting the current settings for graphics output Viewing usage: Void Far SetViewPort (int LEFT, INT TOP, INT RIGHT, INT BOTTOM, INT CLIPFLAG);

#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 results = graphresult (); if (errorcode! = grok) / * an error ocurred * / {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: Settings Visible Graphics Page Number Usage: Void Far SetVisualPage (INT PAGENUM);

#include

#include

#include

INT main (void) {/ * select a driver and mode supports * / / * multiple pages. * / INT GDRIVER = EGA, GMODE = Egahi, ErrorCode; INT X, Y, HT; / * Initialize Graphics and local variables * / INITGRAPH (& GDRIVER, & GMODE, ""); / * read results = graphresult (); if (errorcode! = grok) / * an error occrred * / {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 draking * / 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 PAG E # 1: "); getch (); / * select page # 1 as the visible page * / setvisualpage (1); / * clean up * / getch (); closegraph (); return 0;} function name: setWritemode Function: Setting the output mode of the drawing of graphics mode: Void Far setWriteMode (int mode); program case: # 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 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 * /} xmax = getmaxx (); ymax = getMaxy (); / * select xor drawing mode * / setwritemode; / * 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 a signal of a signal: int signal (int SiG, SIGFUN FNAME); program: / * This Example Installs A Signal Handler Routine for SIGFPE, CATCHES An Adju stment 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 return = 3 * /} int main (void) { Signal (SIGFPE, CATCHER); ASM MOV AX, 07FFFH / * AX = 32767 * / AX = 32767 * / asm incov / * cause overflow * / / / * the handler set ax i 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 / * does not activate * / return 0.; } Function name: SIN function: sinusoidal function usage: double sin (double x); program case: # includ # 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 Strove Function Usage: Double Sinh (Double X); Procedure: #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 function: Perform a pending period: unsigned sleep (unsigned seconds); program: #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 Features: Open a shared file usage: int sithname, int access, int shflag, int permiss; program: #include

#include

#include

#include

#include

#include

INT main (void) {int Handle; int status; "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 ALLOWED / N "); Close (Handle); RETURN 0;} function name: Sound function: Open PC speaker with specified frequency: void Sound (unsigned frequency); program: / * Emits a 7-Hz Tone for 10 Seconds. Your PC May Not Be Able To Emit A 7-Hz Tone. * / #includeint main (void) {Sound (7); DELAY (1000); noid (); return 0;} function name: spawnl Features: Created And run a subscriber usage: int Spawnl (int MODE, CHAR * PATHNAME, CHAR * ARG0, Arg1, ... argn, null); example: #include

#include

#include

INT main (void) {int result; clrscr (); result = spawnl (p_wait, "tcc.exe", null; if (result == -1) {PERROR ("Error from spawnl"); exit (1) } return 0;} function name: spawnle function: Create and run subsurge usage: int Spawnle (int mode, char * pathname, char * arg0, arg1, ..., argn, null); example: / * spawnle () eXample * / #include

#include

#include

INT main (void) {int result; clrscr (); result = spawnle (p_wait, "tcc.exe", null, null; if (result == -1) {PERROR ("Error from spawnle"; exit 1);} return 0;} function name: Sprintf function: send formatted output to string usage: int sprintf (char * string, char * farmat [, argument, ...]); program case: #include

#include

INT main (void) {Char Buffer [80]; Sprintf (Buffer, "An Approximation Of PI IS% F / N", M_PI); PUTS (Buffer); Return 0;} function name: SQRT function: Calculate square root method: Double SQRT (Double X); program case: #include

#include

INT main (void) {double x = 4.0, result; result = SQRT (x); Printf ("The Square Root OF% LF IS% LF / N", X, Result; Return 0;} function name: SRAND function : Initializing random number generator usage: void Srand (unsigned seed); program: # include # include

#include

INT main (void) {INT I; TIME_T T; SRAND (& T)); Printf ("Ten Random Numbers from 0 to 99 / N / N"); for (i = 0; i <10; i ) Printf ("% D / N", RAND ()% 100); return 0;} function name: SSCANF function: Perform formatting input from strings: int sscanf (char * string, char * format [ , argument, ...]);: #include

#include

Int main (void) {char Label [20]; char name [20]; int entries = 0; int loop, age; double salary; struct entry_struct {char name [20]; int Age; float salary;} entry [20 ]; / * Input a label as a string of characters * / printf ("/ N / N / N / 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 * / 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 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, agn 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 INPUT * / Printf ("/ N / NTABLE% S / N", Label; Printf ("Compiled BY% S AGE% D $% 15.2LF / N ", Name, AGE, SALARY); Printf (" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------- / N "); for (loop = 0; loopprintf ("% 4D |% -20s |% 5D |% 15.2LF / N ",

LOOP 1,

Entry [loop] .name,

Entry [loop] .age,

Entry [loop] .salary;

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

Return 0;

}

Function name: STAT function: read open file information usage: int stat (char * pathname, struct stat * buff); program case: #include

#include

#include

#define filename "TEST. $$$" int main (void) {struct statbuf; file * stream; / * open a file for update * / if ("FileName," W ") == null ) {fprintf (stderr, "cannot open output file./N"); return (1);} / * get information about the file * / stat (filename, & statbuf); fclose (stream); / * Display the information returned * / if (statbuf.st_mode & s_ifi) PRINTF ("Handle Refers to a Device./N); if (statbuf.st_mode & s_ifreg) Printf (" Handle Refer to an ORDINARY FILE./N "); if (Statbuf .st_mode & s_iread) Printf ("User Has Read Permission On File./N); if (statbuf.st_mode & s_iwrite) Printf (" User Has Write Permission on File./N); Printf ("Drive Letter Of File :% C / N ", 'a' statbuf.st_dev); Printf (" Size of File in Bytes:% LD / N ", Statbuf.st_size; Printf (" Time File Last Opened:% S / N ", CTIME (& statbuf.st_ctime); Return 0;} function name: _status87 function: Take floating point status usage: unsigned int _status87 (void); program: # includ # include

INT main (void) {float x; double y = 1.5e-100; printf ("status 87 before error:% x / n", _status87 ()); x = y; / * <- force an error to occur * / y = x; Printf ("status 87 after error:% x / n", _status87 ()); return 0;} function name: STIME function: Setting time usage: int 2; program: #include

#include

#include

INT main (void) {TIME_T T; STRUCT TM * Area; T = Time (NULL); Area = LocalTime (& T); Printf ("Number of Seconds Since 1/1/1970 IS:% LD / N", T) PRINTF ("Local Time IS:% S", Asctime (Area)); T ; Area = LOCALTIME (& T); Printf ("Add A Second:% S", Asctime (Area)); T = 60; Area = LocalTime (& T); Printf ("Add A Minute:% S", Asctime (AREA)); T = 3600; Area = LocalTime (& T); Printf ("Add An Hour:% S", Asctime (Area) ); T = 86400L; Area = localtime (& T); Printf ("Add A Day:% S", Asctime (Area)); T = 2592000L; Area = LOCALTIME (& T); Printf ("Add A Month: % s ", asctime (area); t = 31536000L; Area = localtime (& T); Printf (" Add A Year:% S ", Asctime (Area)); Return 0;} function name: STPCPY function: copy A string to another usage: char * stpcpy (char * destin, char * source); program case: # include # include

INT main (void) {char string [10]; char * str1 = "abcdefghi"; stpcpy (string, str1); Printf ("% s / n", string); return 0;} function name: strcat function: character String splicing function: char * strcat (char * destin, char * source); program case: #include

#include

INT main (void) {char Destination [25]; char * blank = "", * c = "c ", * borland = "borland"; strcpy (destination, borland); strcat (destination); STRCAT , C); Printf ("% s / n", destination); RETURN 0;} function name: strchr function: Find the first match of the given character in a string / usage: char * STRCHR (char * Str, char c); program example: #include

#include

Int main (void) {char string [15]; char * ptr, c = 'r'; strcpy (string, "this is a string"); ptr = strChr (string, c); if (ptr) printf (" The Character% C IS At Position:% D / N ", C, PTR-String; Else Printf (" THE Character Was Not Found / N); Return 0;} Function Name: STRCMP Function: String Comparison: Int STRCMP (Char * STR1, CHAR * STR2); Questions: # include # include

INT main (void) {char * buf1 = "aaa", * buf2 = "bbb", * buf3 = "ccc"; int PTR; PTR = strcmp (buf2, buf1); if (PTR> 0) Printf ("buffer 2 IS Greater Than Buffer 1 / N "); Else Printf (" Buffer 2 IS Less Than Buffer 1 / N "); PTR = StrCMP (BUF2, BUF3); if (Ptr> 0) Printf (" Buffer 2 is Greater Than Buffer 3 / N "); Else Printf (" Buffer 2 IS Less Than Buffer 3 / N "); Return 0;} Function Name: Strncmpi Features: Compares a part of a string with another string, regardless of case: INT STRNCMPI (Char * STR1, CHAR * STR2, UNSIGNED MAXLEN);

#include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR; PTR = STRCMPI (BUF2, BUF1); if (PTR> 0) Printf ("Buffer 2 is Greater Than Buffer 1 / n "); if (ptr <0) Printf (" Buffer 2 IS Less Than Buffer 1 / N "); if (PTR == 0) Printf (" Buffer 2 Equals Buffer 1 / N "); return 0;} function Name: STRCPY function: String copy usage: char * STRCPY (Char * str1, char * str2); program case: #include

#include

INT main (void) {char string [10]; char * str1 = "abcdefghi"; strcpy (string, str1); printf ("% s / n", string); return 0;} function name: strcspn function: in String Find a paragraph usage of the first given character set content: int standardspn (char * str1, char * STR2); program case: #include

#include

#include

INT main (void) {char * string1 = "1234567890"; char * string2 = "747dc8"; int LENGTH; length = strcspn (string1, string2); Printf ("Character WHERE STRINGS INTERSECT IS AT POSITION% D / N", LENGTH); RETURN 0;} function name: strDUP function: copy the string to the newly built location: char * strdup (char * str); program case: # include # include

#include

INT main (void) {char * dup_str, * string = "abcde"; dup_str = strdup (string); Printf ("% s / n", dup_str); free (dup_str); Return 0;} function name: Stricmp function : Compare two string uses in case in cases: int Strics (Char * str1, char * str2); program case: #include

#include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR; PTR = Stricmp (BUF2, BUF1); if (PTR> 0) Printf ("Buffer 2 Is Greater Than Buffer 1 / n "); if (ptr <0) Printf (" Buffer 2 IS Less Than Buffer 1 / N "); if (PTR == 0) Printf (" Buffer 2 Equals Buffer 1 / N "); return 0;} function Name: STRERROR Function: Returns a pointer usage of error message string: char * strerror (int errnum); program: #include

#include

INT main (void) {charffer; buffer = strerror (errno); Printf ("Error:% S / N", Buffer; Return 0;} function name: strcmpi function: Put a string with another comparison, no matter Size / write usage: int strcmpi (char * str1, char * str2); program case: #include

#include

INT main (void) {char * buf1 = "bbb", * buf2 = "bbb"; int PTR; PTR = STRCMPI (BUF2, BUF1); if (PTR> 0) Printf ("Buffer 2 is Greater Than Buffer 1 / n "); if (ptr <0) Printf (" Buffer 2 IS Less Than Buffer 1 / N "); if (PTR == 0) Printf (" Buffer 2 Equals Buffer 1 / N "); return 0;} function Name: STRNCMP Function: String Comparison Usage: Int StrMP (Char * STR1, CHAR * STR2, INT MAXLEN); Procedure: #include

#include

Int main (void) {char * buf1 = "aaabbb", * buf2 = "bbbccc", * buf3 = "ccc"; int PTR; PTR = Strncmp (BUF2, BUF1, 3); if (PTR> 0) Printf "Buffer 2 IS Greater Than Buffer 1 / N"); Else Printf ("Buffer 2 IS Less Than Buffer 1 / N); PTR = Strncmp (BUF2, BUF3, 3); if (Ptr> 0) Printf (" Buffer 2 is Greater Than Buffer 3 / N "); Else Printf (" Buffer 2 IS Less Than Buffer 3 / N "); Return (0);} Function Name: Strncmpi Features: Part of the string with another string Part of the comparison, regardless of case: int strncmpi (char * str1, char * str2); program case: # include # include

INT main (void) {char * buf1 = "bbbccc", * buf2 = "bbbccc"; int PTR; PTR = Strncmpi (BUF2, BUF1, 3); if (PTR> 0) Printf ("Buffer 2 is Greater Than Buffer 1 / n "); IF (PTR <0) Printf (" Buffer 2 IS LESS THAN Buffer 1 / N "); if (PTR == 0) Printf (" Buffer 2 Equals Buffer 1 / N "); Return 0; } Strncpy function: String copy usage: char * STRNCPY (Char * Destin, Char * Source, int Maxlen;): #include

#include

INT main (void) {char string [10]; char * str1 = "abcdefghi"; strncpy (strn, str1, 3); string [3] = '/ 0'; Printf ("% s / n", string) RETURN 0;} function name: Strnicmp function: non-focused comparison of two strings: int Strnicmp (Char * STR1, CHAR * STR2, UNSIGNED MAXLEN); program case: #include

#include

INT main (void) {char * buf1 = "bbbccc", * buf2 = "bbbccc"; int PTR; PTR = Strnicmp (BUF2, BUF1, 3); if (PTR> 0) Printf ("Buffer 2 is Greater Than Buffer 1 / n "); IF (PTR <0) Printf (" Buffer 2 IS LESS THAN Buffer 1 / N "); if (PTR == 0) Printf (" Buffer 2 Equals Buffer 1 / N "); Return 0; } Function Name: STRNSET Function: Set all characters in a string to specify character usage: char * strnset (char * str, char ch, unsigned n); program case: # include # include

INT main (void) {char * string = "abcdefghijklmnopqrstuvwxyz"; char letter = 'x'; Printf ("String Before Strnset:% S / N", String); strnset (String, Letter, 13); Printf ("String After strnset:% S / N ", String); Return 0;} function name: strpbrk function: Find a character usage in a set of gauges: char * strpbrk (char * str1, char * str2); #include

#include

int main (void) {char * string1 = "abcdefghijklmnopqrstuvwxyz"; char * string2 = "onm"; char * ptr; ptr = strpbrk (string1, string2); if (ptr) printf ( "strpbrk found first character:% c / n ", * ptr); Else Printf (" strpbrk Didn't Find Character in set / n "); return 0;} function name: STRRCHR function: Find the last occurrence of the specified character in the string: char * STRCHR Char * STR, CHAR C);: #include

#include

Int main (void) {char string [15]; char * ptr, c = 'r'; strcpy (string, "this is a string"); ptr = strrchr (string, c); if (ptr) printf ("" The character% C is at position:% D / N ", C, PTR-STRING); Else Printf (" THE Character Was Not Found / N "); Return 0;} Function Name: Strrev Function: String Dumps: char * Strrev (char * STR); program case: #include

#include

INT main (void) {char * forward = "string"; Printf ("Before Strrev ():% S / N", Forward); strRrev (Forward); Printf ("After strrev ():% s / n", Forward); RETURN 0;} function name: strsET function: set all characters in a string to specify character usage: char * str, char c); program case: # include # include

INT main (void) {char string [10] = "123456789"; char Symbol = 'c'; Printf ("Before strs ():% s / n", string; string, Symbol; printf After strs ():% s / n ", string); Return 0;} function name: strspn function: Find the first appearance of subsets of the specified character set in the string: int Strspn (Char * str1, char * STR2); example: #include

#include

#include

INT main (void) {char * string1 = "1234567890"; char * string2 = "123DC8"; int LENGTH; length = strspn (string1, string2); Printf ("Character WHERE STRINGS DIFFER IS AT POSITION% D / N", Length); RETURN 0;} function name: strsTR function: Find the first appearance usage of specified strings in the string: char * str (char * str1, char * str2); example: #include

#include

INT main (void) {char * str1 = "borland International", * str2 = "nation", * ptr; PTR = strs (str1, str2); Printf ("The Substring IS:% S / N", PTR); Return 0;} function name: Strtod function: convert a string to Double type value: Double Strtod (Char * Str, Char ** Endptr);: #include

#include

INT main (void) {char INPUT [80], * endptr; Double Value; Printf ("Enter A Floating Point Number:"); Gets (INPUT); Value = Strtod (Input, & Endptr); Printf ("THE STRING IS % s the number is% lf / n ", input, value); returno 0;} function name: STRTOK function: Find a word usage separated by a divided tie specified in the second string: char * STRTOK (char * * STR1, CHAR * STR2);

#include

INT main (void) {char input [16] = "abc, d"; char * p; / * STRTOK Places A null terminator in front of the token, if found * / p = strtok (input, ","); IF (p) Printf ("% s / n", p); / * a second call to start with a null as the first parameter returns a pointer to the character following the token * / p = strtok (null, "," ); if (p) Printf ("% s / n", p); return 0;} function name: strtol function: Transfer string to long integer usage: long strtol (char * str, char ** endptr, int base Application: # include # include

INT main (void) {char * string = "87654321", * endptr; long lnumber; / * string, "string, & endptr, 10); printf (" string =% s long = % ld / n ", string, lnumber; return 0;} function name: strupr function: convert lowercase letters in the string to uppercase letters usage: char * strupr (char * STR); program: #include

#include

INT main (void) {char * string = "abcdefghijklmnopqrstuvwxyz", * ptr; / * converts String to Up Upper Case Characters * / PTR = STRUPR (String); Printf ("% S / N", PTR); Return 0;} Function Name: SWAB Function: Switch byte Usage: Void Swab (Char * from, Char * To, INT NBYTES); Certificate

#include

#include

Char Source [15] = "RFNA KoblRNA D"; Char Target [15]; int Main (void) {swab (Source, Target, Strlen (Source)); Printf ("this is target:% s / n", Target ); RETURN 0;} function name: system function: send a DOS command usage: int system (char * Command); program: #include

#include

INT main (void) {PrintF ("about to spawn command.com and run a dos command / n"); system ("dir"); Return 0;} function name: SBRK function: change data segment spatial location 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: Performing Format Input Usage: int Scanf (Char * Format [ , argument, ...];: # incrude # include

Int main (void) {char Label [20]; char name [20]; int entries = 0; int loop, age; double salary; struct entry_struct {char name [20]; int Age; float salary;} entry [20 ]; / * Input a label as a string of characters * / printf ("/ N / N / N / 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 * / 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 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, agn 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 INPUT * / Printf ("/ N / NTABLE% S / N", Label; Printf ("Compiled BY% S AGE% D $% 15.2LF / N ", Name, AGE, SALARY); Printf (" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------- / N "); for (loop = 0; loopprintf ("% 4D |% -20s |% 5D |% 15.2LF / N ",

LOOP 1,

Entry [loop] .name,

Entry [loop] .age,

Entry [loop] .salary;

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

Return 0;

}

Function Name: SearchPath Features: Search DOS Path Usage: Char * SearchPath (Char * FileName); Certificate: #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 fill the elliptical fan area: Void Far Sector (int x, int y, int standle, int endangle); program: #include

#include

#include

#include

INT main (void) {/ * request auto detection * / int gDriver = detect, gmode, errorcode; int midx, midy, i; int standle = 45, endangle = 135; int XRAD = 100, yrad = 50; / * 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 pattern * / 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: reading Register value usage: void segread (struct Sregs * segtbl); program case: #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 function: Setting graphics output activity page Usage: Void Far setActivePage (int Pagenum Application: #include

#include

#include

#include

INT main (void) {/ * select a driver and mode supports * / / * multiple pages. * / INT GDRIVER = EGA, GMODE = Egahi, ErrorCode; INT X, Y, HT; / * Initialize Graphics and local variables * / INITGRAPH (& GDRIVER, & GMODE, ""); / * read results = graphresult (); if (errorcode! = grok) / * an error occrred * / {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 draking * / 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 PAG E # 1: "); getch (); / * select page # 1 as the visible page * / setvisualpage (1); / * clean up * / getch (); closegraph (); return 0;} function name: setAllPallette Function: Change all palette color usage by specifying: Void Far SetallPallette (Struct Palette, Far * Pallette);

#include

#include

INT main (void) {/ * request auto detection * / int gDriver = detect, gmode, errorcode; struct pastettype pal; int color, maxcolor, ht; int y = 10; char msg [80]; / * 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 * /} maxColor = getMaxColor (); ht = 2 * TextHeight ("w"); / * grab a copy of the palette * / getpalette (& par); / * Display the default paste 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 para} / * restpalette (& Pal); / * clean up * / getch ); closegraph (); RETURN 0;} function name: setaspectratio function: set graphical aspect ratio: Void Far setaspectratio (int XASP, int yasp);

#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 results = graphresult (); if (error (error) / * an error opcurred * / {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 (); / * clar the screen * / clearden * / clearDeffic (); / * Adjust the aspect for a wide circle * / setaspectratio (XASP / 2, YASP); Circle (MIDX, MIDY, 100); getCh (); / * adjust the aspect for a narrow circle * / clearden (); setaspectratio (XASP, YASP / 2); Circle (MIDX, MIDY, 100); / * CLOAN UP * / GETCH (); Closegraph (); Return 0;} function name: setBkcolor function: Set the current background with palette Color Usage: Void Far SetBkcolor (int color);

#include

#include

INT main (void) {/ * select a driver and mode supports * / / * multiple background colors. * / int gahi = EGA, GMODE = Egahi, ErrorCode; int BKCOL, MaxColor, x, y; char msg [80] ; / * 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 * /} / * 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 * / clearden (); / * 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 previously allocated DOS storage size usage: int setBlock (int seg, int news) ;

#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 paragraphone available IS% D / N", STAT) Freemem (segp); Return 0;} function name: setbuf function: Put the buffer with flow connections: void setbuf (file * steam, char * buf); program: # include / * bufsiz is defined in stdio. h * / char outbuf [buffs]; 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/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); RETU RN 0;} function name: setcbrk function: Set control-break usage: int setcrk (int value); program case: #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: Setup current painting Line color usage: Void Far setColor (int color); program case: #include

#include

#include

#include

INT main (void) {/ * select a driver and mode 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 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 * /} / * 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 * / clearden (); / * select a new background color * / setcolor (color); / * Output a message * / sprintf ( MSG, "Color:% D", Color; OutTextxy (X, Y, MSG); getCh ();} / * clean up * / closegraph (); Return 0;} function name: setdate function: set DOS date usage: void setdate (struct date * dateblk); program: # includ # include

#include

INT main (void) {struct date; struct date save_date; getdate; "Original Date: / N"); System ("Date"); reset.da_year = 2001; reset.da_day = 1; reset .da_mon = 1; setdate; "DATE ​​AFTER SETTING: / N"); System ("Date"); setdate; "Back to Original Date: / n"); System (" Date "); Return 0;} function name: setDisk function: Set current disk drive usage: int setDisk (int drive); program case: #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 function: set disk transfer area Address Usage: Void Setdta (Char Far * DTA); Procedure: # 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) {Perror ("Error Creating File"); EXIT (1);} / * Save Old DTA And set new dta * / save_dta = getdta (); setdta (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 To File * / IF (BDOSPTR (0x10, & BLK, 0) == -1) {PERROR ("Error Closing File"); EXIT (1);} / * reset the Old DTA * / setdta (save_dta); Return 0;} function Name: setFillPattern function: Select user-defined fill mode usage: Void Far SetFillPattern (Char Far * Upattern, int color); program: #includ e

#include

#include

#include

INT main (void) {/ * request auto detection * / int gDriver = detect, gmode, errorcode; int maxx, maxy; / * a user defined Fill Pattern * / char pattern [8] = {0x00, 0x70, 0x20, 0x27 , 0x24, 0x24, 0x07, 0x00}; / * 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 * /} 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: Setting Packing Mode and Color Usage: Void Far SetFillStyle (int pattern, int color);

#include

#include

#include

/ * The names of the fill 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 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; for (style = Empty_fill; style

#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_rour = 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 usage of internal graphics buffers: unsigned far setgraphbufsize (unsigned bufsize);

#include

#include

#define buffs 1000 / * InterNal graphics buffer size * / int main (void) {/ * request auto detection * / int gDriver = detect, gmode, erroorcode; int x, y, oldsize; char msg [80]; / * set the size of the internal graphics buffer * / / * before making a call to initgraph * / oldsize = setgraphbufsize (BUFSIZE);. / * 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 * /} 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 Set graphic mode and clear screen usage: Void Far setgraphmode (int mode);

#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 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 * /} 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 U p * / getch (); closegraph (); return 0;} function name: setjmp function: non-local transfer method: int setjmp (jmp_buf env); program case: # 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 subs (void) {longjmp (jumper, 1);} function name: setLinesTyle Features: Setup Line width and type usage: Void Far setLinesTyle (int LinestYPE, Unsigned Upattern); program: #include

#include

#include

#include

#include

/ * the names of the line styles 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 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; / * 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 * / R Ectangle (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 value to storage area: void setmem (void * addr, int Len, char value); program case: # includ # 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 Features: Setting Open File Method: Int SetMode (int Handle, Unsigned Mode); program: #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: Changing the color usage of the palette: 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 itis = graphresult (); if (errorcode! = grok) / * an error ire {Printf ("graphics error:% s / n", GrapherrorMSG ("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 usage of IBM8514 graphics card: Void Far setRGbpalette (int Colornum, Int Red, Int Green, INT Blue); #include

#include

#include

#include

INT main (void) {/ * select a driver and mode this 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 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 * /} / * Grab a copy of the paperte * / getpalette (& par); / * create gray scale * / for (i = 0; ISETRGBPALETTE (Pal.colors [i], i * 4, i * 4, i * 4);

/ * Display the gray scale * / ht = getmaxy () / 16; xmax = getmaxx (); y = 0; for (i = 0; i

{

SetFillStyle (Solid_Fill, i);

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

Y = HT;

}

/ * CLOAN UP * / GETCH (); Closegraph (); Return 0;} Function Name: SetTextJustiFY function: Alignment for graphics function: Void Far setTextJustify (int horiz, int vert); program: #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, erroorcode; int MIDX, Midy, HJ , vj; char msg [80]; / * Initialize graphics and local variables * / initgraph (& gdriver, & gmode, ""); / * read results = graphresult (); if (erroorcode! = grok) / * An error ocurred * / {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); line (x, y-4, x, y 4);} function name: setTextStyle function: Set the current text attribute for graphic output: Void Far setTextStyle Int font, int direction, char size); program: # include # include

#include

#include

/ * the names of the text styles supported * / char * fname [] = {"Default Font", "Triplex Font", "Sman 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 results = graphresult (); if (ErrorCode! = GROK) / * An error accurred * / {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: Set the current text attribute for graphics output: Void Far setTextStyle (int FAR setTextStyle (int FAR SIZE); program: # includ # include

#include

#include

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

New Post(0)