char 016, dir(MRIDTR
hae new dt (018)
fat main(vots)
36 (getenaie(0, old dish) (
pezzor("getcurdir(}"1;
exit (Ui;
pelate ("current dinectory is: \\te\e”
Af (ebaie CN
persor(Pehdir() "1:
exc (lly
XE (gotourdir(0, nex di
perror("geteardir()")
exit
print (*Curcent dizectory £2 nov: \\is\n*, now dir}:
printf (M\nchanging back to orignal disectory: \Wis\n", old diel;
Af (ehdirfold aleh) |
perzorite
exits
return 0
Function
Syntax.
Sets current disk drive.
include
int _chdrivefint drive);
Chapter 2, The run-time foray n—chdrive
Remarks _chdrive sets the current drive to the one associated with drive: I for A,2
Jor B, 3 for C, and so on.
Retum value _chdrive returns 0 if the current drive was changed successfully;
otherwise, itreturns -1
See Also _dos_setdrive,_getdrive
Example
Aincluse
int main oid)
c
ls o
print (“Successfully changed to drive C:\n");
else
printf (*Canaot change to drive c:\e",
'
_chmod
Function Gets or sets DOS file attributes.
Syntax. include
include
int chmod(const char *path, int func [, int attrib);
Remarks _chmod can either fetch or set the DOS file attributes. If func is 0, the
Function returns the current DOS attributes for the file. If funcis 1, the
attribute is set to attrib.
atin can be one of the following symbolic constants (defined in dos.h):
FA RDONLY Read-only attribute
FA HIDDEN Hidden file
FA SYSTEM System file
FA_LABEL Volume label
FA_DIREC Directory
FAARCH Archive
72 Borland C+ Ubrary Reference
Return value
See ako
Example
-chmod
‘Upon successful completion, _ehmod returns the file attribute word;
otherwise, it returns a value of -1.
In the event of an error, the global variable erm is set to one of the
following:
ENOENT Path or file name not found
EACCES — Permission denied
chmod, _creat
‘Hizclose
include
se
fnt got_{ile_aterib(ehar +Filenane)
sm mainivoid)
(
char flenen128);
ena)
printf ("Path or file not found.\o"):
cave RICGES ¢ printE(*Pennission denied. \n");
break
dotaate smber: ern)
tse (
Af taterib & ROOM)
prince("ts 18 read-only.\n", fllesanel:
£ latteib & 7008)
priate (Me 18 nidden.\nt, fen)?
Le (attetb « ea s1sTE)
AE (autei 6 FA_LABED)
peinte(*%s ie volume label. a, filename);
ff (otteib & Pa ouReC)
print ("he G2 a direct
Sf (attrib « Pa ARCH)
printi(*te 48 an archive file
ye, lenaxel
filename
Chapter 2, The run-time library 73chmod
chmod
'
return 0;
'
1% returns the attributes of a bot file +/
int get_{ile attrib(ehar *filonans)
return(_chnod(filerane, 0)1;
Funetion
syntax.
Remarks
Return value
See also
Example
7
Changes file access mode,
include
int chmod(const char *path, int amode);
Ta | weer [ were [or my
‘chmod sets the file-access permissions of the file given by path according
to the mask given by amode. path points to a string; *path isthe first
character of that string,
amade can contain one or both of the symbolic constants $ IWRITE and
S-IREAD (defined in sys\stat.h).
Value of amode ‘Access permission
SIWRITE
SUIREAD
SUIREADIS_IWRITE
Permission to write
Permission to read
Permission to read and write
Upon successfully changing the file access mode, chmod returns 0.
Otherwise, chmod returns a value of 1.
In the event of an error, the global variable errno is set to one of the
following:
ENOENT
BACCES,
access, _chmod, fstat, open, sopen, stat
Path or file name not found
Permission denied
Hisclude
Hacivse
include do.
Hinelude
Hisclude
Borland C++ Library Reference
chmod
st main(vois)
1
chsize
jar filename 64];
at anode;
4:
f (etat(fllenane, sstbaf) I= 0) |
‘perror ("Unable to get file information");
retin}
else {
priate "changing to read-writels
‘anode = §_IRERD|S_ WRITE
'
Af (otwod{ilenane, anode) = 0) (
error (Unable to change file node")
seturn(i);
retueo(0)
Function
syntax
Remarks
(Chapter 2, The run-time foray
Changes the file size.
include
int chsize(int handle, long size);
chsize changes the size of the file associated with handle, Itcan truncate or
extend the file, depending on the value of size compared to the file's
original siz.
The mode in which you open the file must allow writing.
Ifehsize extends the fie, it will append null characters (\0). It truncates
the file, all data beyond the new end-of-fle indicator is lost.
%| chsize
Retun value
See also
Example
circle
‘On success, chsize returns 0. On failure, it returns ~1 and the global
variable errno is set to one of the following:
EACCESS Permission denied.
EBADF Bad file number
ENOSPC — UNIX—not DOS
close, creat, creat, open
ficelade cering >
Hinelade
Heelude
nt main(vois)
1
At bande
nar buf(L1) = "0123686708
(+ coeate 2 text file containing 10 bytes 4/
Randle = open *OONMY.FTL", 0. CRAY
e(handle, bat, strlen (bul)|;
+ teuncate the
0 5 bytes in alze +7
chsize(bandle,
> close the fie +/
cleve handle):
urn O;
Function
‘Syntax
Remarks
-
Return value
%
Draws a circle of the given radius with its center at (9).
include
void far circle(int x, int y, int radius);
circle draws a citcle in the current drawing calor will its enter at Gy)
and the radius given by radius.
The linestyle parameter does not affect arcs, circles, ellipses, or pie slices.
Only the thickness parameter is used.
If your circles are not perfectly round, adjust the aspect ratio.
None.
Borland C+ Library Reference
See also
Example
clear87
Funetion
‘Syntax
are, ellipse, fllellipse, gotaspectratio, sector, setaspectratio
Hnetude
include etal.
Hinelade
inelude
int main oid)
jest autodetection */
nt gdriver = OSTECT, guade, exrorcede;
int mide, aidy, radius = 100;
(+ intetalize graphics and
gdciver, ‘node
J+ road result of initialization */
ecroreode = graphrestl¢
AF (erzorcode '= geOk) | /* an
nte("Geaphies exeor: As\a", grape
nt g{"Press any Key to belt")
"
ormsgerrorcode))
oe
sminate with en error code */
}
re = getmacet) J 2;
sy = geteaxy() / 2
setoolor getsexcolor(})
1° daw he elxele *7
elecle(nise, migy, radius);
1 clean op */
etch
losege
return 0;
0s
Clears floating-point status word,
include
unsigned int _clear87 (void);
[| Winton | wre [or my
Chapter 2. The run-time library
circle
7l _clear87
Remarks
Retum value
See ako
Example
cleardevice
Function
syntax
Remarks
Retun value
See also
Example
78
_clear87 clears the floating-point status word, which is a combination of
the 80x87 status word and other conditions detected by the 80x87
exception handler.
‘The bits in the value returned indicate the floating-point status before it
was cleared, For information on the status word, refer to the constants,
defined in float.h.
_controls7,_fpreset, _status87
Hrelude
Hixclnde
int main oid)
c
fat x:
oubie y = 156-100
Printf{(*astatus 87 before error: 4x\a", _sta
x= yi [* create underflow and precision Toss */
printf ("statue 87 after error: tt\a", _statws67())
“clear?
Prince "status 67 after
yen
return 0;
jar: xn", _statusb7(})
‘Clears the graphics screen.
Winlude
void far cleardevice(void);
BS [WR | Wawe | ere [Oey
include eat.
Hrelude
Borland C++ Library Reference
int main(void)
1
1+ request autedetection #/
int gériver = DEIGCT, gnode, errorcoder
J+ initialize graphies and local variables */
initgraph(agdriver, sgnode, °");
(> read result of initialization */
extorende » graphreenlt );
AE (extorcode '~ gr0k) (
printf ("Graphics erzor: @s\n"
printt("2rese any Rey to bale")?
etch:
exe;
1
ferrorcode
1+ teaminate with on excor code */
aide = geteaxx() / 2:
aidy = goteaxy() / 2%
sateolorigetmaxcolee(}
1+ foe centering serean nessages */
sottent justify (CENTER P=XT, COVTER TE
1+ output a message to the sereas */
cattextay mide, midy, "Press any key to clear the screen:)
getchtl; (ait for a key */
leardevice();/* clear the screen 47
1 outpat another message */
ide, misy, “Pees any hay to quit
event
leseseeph(e
return 0;
clearerr
Function Resets error indication,
‘Syntax include
void clearerr(FILE *stream);
Chapter 2, The run-time brary
cleardevice
nclearer
Remarks
Retum value
See oko
Example
clearviewport
Function
syntax
Remarks
Retun value
clearerr resets the named stream’s error and end-of-file indicators to 0.
Once the error indicator is set, stream operations continue to return error
status until a call is made to clearerr or rewind,
The end-of-file indicator is reset with each input operation,
None.
01, feof, ferror, perror, rewind
Hinelude
nt nein vote
Prue ¥p:
char chr
1+ open a file for writing +7
fp = fopen DIMM. FEL", *v")
1 force an
ch = fgetortp)
rinte (*\o"
Af (fercortfeh) (
1 display an error message */
peinut (Ervor reading feom DOMMY.FTL\at
(+ reset the extor and 20° sndicators */
earers (fp
felese
return 0;
Clears the current viewport
findude
void far clearviewport(void);
ves
Wnion | MSE [Oey
clearviewport erases the viewport and moves the CP (current position) to
home (0,0), relative to the viewport
None.
Borland C++ Library Reference
See also
Example
cleardevice, getviewsettings, setviewport
include
fnelade
lade
Hiselude
Pou 1 /* activates clipping in viewport */
1* cequost autodetection */
int gdriver + DaTECT, gmade, erzorcode, tt:
iF
lize qraphies and local varlables */
J read sasult of initialisation */
code = grapheesut ()
1 an exror occurred +/
As\o", grapherrornsgersorcode});
print ("Press any key to halt
sgetent
fit /* teminate with an exnor ood */
(getmaxcolor{}):
height
9% massage in default
outtextay(, 0,"
-scroen viewport */
(@, 0) in dofault viewpo
1% create @ smaller vewport */
sotviewport (50, §4, getmxx()-50, getasxy(}-50, CLIO
1 display sone messages */
outtextay 0, 0, "# <= (0, 0) in smaller viewport”
futtextay 0, 2th, “Press any Key to cleat viewport:
etch: 74 valt for a key */
Clearviewport (};_ /* clear the viewport */
7 output ther nozsage */
futtextay 0, 0, "Press any key to quit")
+ etean mp 4
etch
leseseeph()
arn 0
Chapter 2, The run-time llorary
clearviewpor
alclock
close, close
clock Romarks _close and clase close the file associated with handle a file handle
‘biained from a creat, creat, ereatnew, ereattemp, dup, dup2, open, or
Function Determines processor time. open cal.
oe eb These functions do not write a Git character atthe end ofthe file. Ifyou
Rotum value Upon sucessful completion, close and close return 0, Otherwise, these
Fa re eons aot | Carat functions return a value of -1.
i __ose and clase fail if handle is not the handle ofa valid, open file and
Remarks clock can be used to determine the time interval between two events. the global variable errno is set to
i To determine the time in seconds, the value returned by elock should be EBADF _ Bad file number
divided by the value of the macro CLK_TCK. Seealso chsize, close, creat, creatnew, dup, fclose, open, sopen
Return value ‘The elock function retums the processor time elapsed since the beginning es es
ofthe program invocation, Ifthe processor time is not available, or its ieee eee
value cannot be represented, the function returns the value—1 Finca cost
See also time int mintvoid)
{
Example jinctude «tim.» sn bane;
Tinea
Henereny =
maine tanale = open "00m
weitethandle, bu,
ee eee ee 1+ close the fe */
| olay (2000 ceesneae
tnd = lost: recor
print é ("The time was: $f\n", (end - start) / CLK_PCK) 1
turn 0
: closedir
close, close Function Closes a directory stream.
Syntox Hinclude
Function Closes a file. void closedir(DIR “dirp);
‘Syntax #include
int. close(int handle); es [wor] winds | mSTC | Ow only
int closetint handle); oe
aa [Wi] nes [mee To iy Remarks On UNIX platforms, elosedir is available on POSIX-compliant systems.
we Borland C++ Library Reference Chapter 2, The run-time library 83closedir
‘The elosedir function closes the directory stream dip, which must have
been opened by a previous call to opendir. After the stream is closed, dirp
no longer points to a valid directory stream.
Rotun vale If closediris sucessful, it retums 0, Otherwise, closed returns 1 and
sets the global variable era ta
EBADE —Thedirp argument doesnot point toa valid open directory s
See Ato opendi, read, rewind
Example See the example for opend
closegraph
Function Shuts down the graphics system.
Syntax fnclude
‘oid far closegraphivoid;
Remarks closegraph ceallocates all memory allocated bythe graphics system, then
festores the screen to the mode it was in before you called Initgraph. (The
fraphics system deallocates memory, sich asthe drivers, fonts, and an
{hternal buffer, through a cal to graphfreemem)
Retum value None.
See also initgraph, setgraphbutsize
Example finclude
finclade