C language library function (R-class letters)

xiaoxiao2021-03-06  41

Function name: raise

Function: Send a signal to the program being executed

Usage: int Raise (Int Sig);

Example:

#include

Int main (void)

{

INT A, B;

A = 10;

B = 0;

IF (b == 0)

/ * Preempt divide by Zero Error * /

Raise (SIGFPE);

A = a / b;

Return 0;

}

Function name: Rand

Function: Random number generator

Usage: void rand (void);

Example:

#include

#include

Int main (void)

{

INT I;

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: Randbrd

Function: random block reading

Usage: int RANTBRD (Struct FCB * fcbptr, int RECCNT);

Example:

#include

#include

#include

#include

Int main (void)

{

Char Far * Save_dta;

Char line [80], buffer [256];

Struct FCB BLK;

INT I, RESULT;

/ * GET User Input File Name for DTA * /

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

Gets (line);

/ * PUT FILE Name in FCB * /

IF (! PARSFNM (Line, & BLK, 1))

{

Printf ("ERROR in Call to Parsfnm / N);

Exit (1);

}

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

/ * Open file with dos fcb open file * /

BDOSPTR (0x0f, & blk, 0);

/ * SAVE OLD DTA, AND SET New One * /

Save_dta = getdta ();

Setda (buffer);

/ * SET UP INFO for the New DTA * /

BLK.FCB_RECSIZE = 128;

BLK.FCB_Random = 0L;

Result = randbrd (& BLK, 1);

/ * Check Results from randbrd * /

IF (! result)

Printf ("Read OK / N / N");

Else

{

"" ERROR DURING READ ");

Exit (1);

}

/ * Read in data from the New DTA * /

Printf ("The first 128 characters are: / n");

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

Putchar (buffer [i]);

/ * RESTORE PREVIOUS DTA * /

Setdta (Save_DTA); Return 0;

}

Function name: randbwr

Function: random block

Usage: int RANDBWR (struct fcp * fcbptr, int RECCNT);

Example:

#include

#include

#include

#include

Int main (void)

{

Char Far * Save_dta;

Char line [80];

Char buffer [256] = "Randbwr Test!";

Struct FCB BLK;

Int result;

/ * Get new file name from user * /

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

Gets (line);

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

PARSFNM (Line, & BLK, 1);

Printf ("DRIVE #% D File:% 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);

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: Random

Function: Random number generator

Usage: int Random (Int Num);

Example:

#include

#include

#include

/ * Prints a Random Number in the Range 0 to 99 * /

Int main (void)

{

Randomize ();

Printf ("Random Number In The 0-99 Range:% D / N", Random (100));

Return 0;

}

Function name: Randomize

Function: Initializing the random number generator

Usage: void randomize (void);

Example:

#include

#include

#include

Int main (void)

{

INT I;

Randomize (); 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: Read

Function: read from the file

Usage: int in (int Handle, Void * BUF, INT NBYTE);

Example:

#include

#include

#include

#include

#include

#include

Int main (void)

{

Void * BUF;

INT HANDLE, BYTES;

BUF = Malloc (10);

/ *

Looks for a file in The Current Directory Named Test. $$$ And Attempts

To read 10 bytes from it. To Use this example you shop crete the

File Test. $$$

* /

IF ((Handle =

Open ("Test. $$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD) == -1)

{

Printf ("Error Opening File / N);

Exit (1);

}

IF ((bytes = read (Handle, BUF, 10)) == -1) {

Printf ("Read Failed./N");

Exit (1);

}

Else {

Printf ("Read:% D Bytes Read./N", BYTES);

}

Return 0;

}

Function name: Realloc

Finance: Renotes the main memory

Usage: Void * Realloc (Void * PTR, Unsigned Newsize);

Example:

#include

#include

#include

Int main (void)

{

Char * STR;

/ * Allocate Memory for String * /

Str = malloc (10);

/ * Copy "Hello" INTO STRING * /

STRCPY (STR, "Hello");

Printf ("String IS% S / N Address IS% P / N", STR, STR);

Str = Realloc (STR, 20);

Printf ("String IS% S / N New Address IS% P / N", STR, STR);

/ * Free memory * /

Free (STR);

Return 0;

}

Function name: Rectangle

Function: draw a rectangle

Usage: Void Far Rectangle (int LEFT, INT TOP, INT RIGHT, INT BOTTOM);

Example:

#include

#include

#include

#include

Int main (void)

{

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

INT LEFT, TOP, RIGHT, BOTTOM

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

}

Left = getmaxx () / 2 - 50;

TOP = getMaxy () / 2 - 50;

Right = getmaxx () / 2 50;

Bottom = getMaxY () / 2 50;

/ * Draw a rectangle * /

Rectangle (LEFT, TOP, RIGHT, BOTTOM);

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: RegisterBgidriver

Function: Log in to the connected graphics driver code

Usage: int REGISTERBGIDRIVER (Void (* driver));

Example:

#include

#include

#include

#include

Int main (void)

{

/ * Request Auto Detection * /

INT GDRIVER = Detect, Gmode, ERRORCODE

/ * Register a driver what was added into graphics.lib * /

ERRORCODE = RegisterBgidriver (egavga_driver);

/ * Report Any Registration Errors * /

ErrorCode <0)

{

Printf ("Graphics Error:% S / N", GrapherrorMsg (ErrorCode));

Printf ("Press Any Key to Halt:");

Getch ();

EXIT (1); / * Terminate with an error code * /

}

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

/ * Draw a line * /

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

/ * Clean Up * /

Getch ();

Closegraph ();

Return 0;

}

Function name: Remove

Function: Delete a file

Usage: int Remove (char * filename);

Example:

#include

Int main (void)

{

Char file [80];

/ * Prompt for file name to delete * /

Printf ("File to Delete:");

Gets (file);

/ * Delete the file * /

IF (remote (file) == 0)

Printf ("REMOVED% s. / n", file);

Else

PERROR ("remove");

Return 0;

}

Function name: rename

Finance: Rename file

Usage: int Rename (Char * oldname, char * newname);

Example:

#include

Int main (void)

{

Char oldname [80], newname [80];

/ * Prompt for file to rename and new name * /

Printf ("File to Rename:");

Gets (OldName);

Printf ("New Name:");

Gets (newname);

/ * Rename the file * /

IF (Rename (OldName, NewName) == 0)

Printf ("Renamed% S TO% s. / N", OldName, NewName;

Else

PERROR ("Rename");

Return 0;

}

Function name: RestoreCrtMode

Function: Recover the screen mode to the previous IMITGRAPH settings

Usage: Void Far RestoreCrtMode (Void);

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;

}

Function Name: Rewind

Function: Redirect file pointer to a stream

Usage: int Rewind (file * stream);

Example:

#include

#include

Int main (void)

{

File * fp;

Char * fname = "txxxxxx", * newname, first;

NewName = mktemp (fname);

fp = fopen (newname, "w ");

FPRINTF (FP, "Abcdefghijklmnopqrstuvwxyz");

Rewind (fp);

FSCANF (FP, "% C", & first);

Printf ("THE FIRST Character IS:% C / N", First);

Fclose (fp);

REMOVE (NewName);

Return 0;

}

Function name: RMDir

Function: Delete the DOS file directory

Usage: int RMDir (Char * stream);

Example:

#include

#include

#include

#include

#define dirname "Testdir. $$$"

Int main (void)

{

Int stat;

Stat = mkdir (DIRNAME);

IF (! stat)

Printf ("Directory CREATED / N");

Else

{

Printf ("Unable to create Directory / N);

Exit (1);

}

Getch ();

System ("DIR / P");

Getch ();

Stat = RMDIR (DIRNAME);

IF (! stat)

Printf ("/ ndirectory deleted / n");

Else

{

Perror ("/ NUNABLE to DELETE DIRECTORY / N");

Exit (1);

}

Return 0;

}

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

New Post(0)