Function Name: cabs
Function: Calculate the absolute value of a complex number.
Usage: double cabs (struct complex z );
Program example:
# Include
# Include
Int main (void)
{
Struct complex z;
Double val;
Z. x = 2.0;
Z. y = 1.0;
Val = cabs (z );
Printf ("The absolute value of %. 2lfi %. 2lfj is %. 2lf", z. x, z. y, val );
Return 0;
}
Function Name: calloc
Function: allocate primary storage
Usage: void * calloc (size_t nelem, size_t elsize );
Program example:
# Include
# Include
Int main (void)
{
Char * str = NULL;
/* Allocate memory for string */
Str = calloc (10, sizeof (char ));
/* Copy "Hello" into string */
Strcpy (str, "Hello ");
/* Display string */
Printf ("String is % s", str );
/* Free memory */
Free (str );
Return 0;
}
Function Name: ceil
Function: Round Up
Usage: double ceil (double x );
Program example:
# Include
# Include
Int main (void)
{
Double number = 123.54;
Double down, up;
Down = floor (number );
Up = ceil (number );
Printf ("original number % 5.2lf", number );
Printf ("number rounded down % 5.2lf", down );
Printf ("number rounded up % 5.2lf", up );
Return 0;
}
Function Name: cgets
Function: Read strings from the console
Usage: char * cgets (char * str );
Program example:
# Include
# Include
Int main (void)
{
Char buffer [83];
Char * p;
/* There's space for 80 characters plus the NULL terminator */
Buffer [0] = 81;
Printf ("Input some chars :");
P = cgets (buffer );
Printf ("cgets read % d characters:" % s "", buffer [1], p );
Printf ("The returned pointer is % p, buffer [0] is at % p", p, & buffer );
/* Leave room for 5 characters plus the NULL terminator */
Buffer [0] = 6;
Printf ("Input some chars :");
P = cgets (buffer );
Printf ("cgets read % d characters:" % s "", buffer [1], p );
Printf ("The returned pointer is % p, buffer [0] is at % p", p, & buffer );
Return 0;
}
Function Name: chdir
Function: change the working directory
Usage: int chdir (const char * path );
Program example:
# Include
# Include
# Include
Char old_dir [MAXDIR];
Char new_dir [MAXDIR];
Int main (void)
{
If (getcurdir (0, old_dir ))
{
Perror ("getcurdir ()");
Exit (1 );
}
Printf ("Current directory is: \ % s", old_dir );
If (chdir ("\"))
{
Perror ("chdir ()");
Exit (1 );
}
If (getcurdir (0, new_dir ))
{
Perror ("getcurdir ()");
Exit (1 );
}
Printf ("Current directory is now: \ % s", new_dir );
Printf ("Changing back to orignal directory: \ % s", old_dir );
If (chdir (old_dir ))
{
Perror ("chdir ()");
Exit (1 );
}
Return 0;
}
Function Name: _ chmod, chmod
Function: Change the File Access Mode
Usage: int chmod (const char * filename, int permiss );
Program example:
# Include
# Include
# Include
Void make_read_only (char * filename );
Int main (void)
{
Make_read_only ("NOTEXIST. FIL ");
Make_read_only ("MYFILE. FIL ");
Return 0;
}
Void make_read_only (char * filename)
{
Int stat;
Stat = chmod (filename, S_IREAD );
If (stat)
Printf ("Couldn't make % s read-only", filename );
Else
Printf ("Made % s read-only", filename );
}
Function Name: chsize
Function: Change the file size.
Usage: int chsize (int handle, long size );
Program example:
# Include
# Include
# Include
Int main (void)
{
Int handle;
Char buf [11] = "0123456789 ";
/* Create text file containing 10 bytes */
Handle = open ("DUMMY. FIL", O_CREAT );
Write (handle, buf, strlen (buf ));
/* Truncate the file to 5 bytes in size */
Chsize (handle, 5 );
/* Close the file */
Close (handle );
Return 0;
}
Function Name: circle
Function: draws a circle at the center of the given radius (x, y ).
Usage: void far circle (int x, int y, int radius );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy;
Int radius = 100;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}
Midx = getmaxx ()/2;
Midy = getmaxy ()/2;
Setcolor (getmaxcolor ());
/* Draw the circle */
Circle (midx, midy, radius );
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: cleardevice
Function: Clear the graphic screen
Usage: void far cleardevice (void );
Program example:
# Include
# Include
# Include
# Include
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int midx, midy;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}
Midx = getmaxx ()/2;
Midy = getmaxy ()/2;
Setcolor (getmaxcolor ());
/* For centering screen messages */
Settextjustify (CENTER_TEXT, CENTER_TEXT );
/* Output a message to the screen */
Outtextxy (midx, midy, "press any key to clear the screen :");
/* Wait for a key */
Getch ();
/* Clear the screen */
Cleardevice ();
/* Output another message */
Outtextxy (midx, midy, "press any key to quit :");
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: clearerr
Function: indicates a reset error.
Usage: void clearerr (FILE * stream );
Program example:
# Include
Int main (void)
{
FILE * fp;
Char ch;
/* Open a file for writing */
Fp = fopen ("DUMMY. FIL", "w ");
/* Force an error condition by attempting to read */
Ch = fgetc (fp );
Printf ("% c", ch );
If (ferror (fp ))
{
/* Display an error message */
Printf ("Error reading from DUMMY. FIL ");
/* Reset the error and EOF indicators */
Clearerr (fp );
}
Fclose (fp );
Return 0;
}
Function Name: clearviewport
Function: Clear the graphic Area
Usage: void far clearviewport (void );
Program example:
# Include
# Include
# Include
# Include
# Define CLIP_ON 1/* activates clipping in viewport */
Int main (void)
{
/* Request auto detection */
Int gdriver = DETECT, gmode, errorcode;
Int ht;
/* Initialize graphics and local variables */
Initgraph (& gdriver, & gmode ,"");
/* Read result of initialization */
Errorcode = graphresult ();
If (errorcode! = GrOk)/* an error occurred */
{
Printf ("Graphics error: % s", grapherrormsg (errorcode ));
Printf ("Press any key to halt :");
Getch ();
Exit (1);/* terminate with an error code */
}
Setcolor (getmaxcolor ());
Ht = textheight ("W ");
/* 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 messages */
Outtextxy (0, 0, "* <-- (0, 0) in smaller viewport ");
Outtextxy (0, 2 * ht, "Press any key to clear viewport :");
/* Wait for a key */
Getch ();
/* Clear the viewport */
Clearviewport ();
/* Output another message */
Outtextxy (0, 0, "Press any key to quit :");
/* Clean up */
Getch ();
Closegraph ();
Return 0;
}
Function Name: _ close, close
Function: Close the file handle.
Usage: int close (int handle );
Program example:
# Include <