Part IV • Documenting the Differences
atof()
Header: |
math.h & stdlib.h |
Syntax: |
double atof(const char * szString); |
Description: |
Converts characters to a double value. |
Parameters: |
szString—Pointer to a string containing the character represen- |
|
tation of the double number. |
Returns: |
A double value. |
Example: |
dValue = atof(“1234.56”); |
|
/* dValue will be 1234.56 */ |
Note: |
Conversion continues until the first invalid character is reached. |
|
You can test errno to determine any errors that occurred. |
atoi()
Header: |
stdlib.h |
Syntax: |
int atoi(const char * szString); |
Description: |
Converts characters to a short integer value. |
Parameters: |
szString—Pointer to a string containing the character represen- |
|
tation of the integer. |
Returns: |
A short integer. |
Example: |
nValue = atoi(“1234”); |
|
/* nValue will be 1234 */ |
Note: |
Conversion continues until the first invalid character is reached. |
|
You can test errno to determine any errors that occurred. |
atol()
Header: stdlib.h
Syntax: long atol(const char * szString);
Part IV • Documenting the Differences
calloc()
Header: |
malloc.h & stdlib.h |
Syntax: |
void * calloc(size_t nCount, size_t nSize); |
Description: |
Allocates an array. |
Parameters: |
nCount—Number of elements. |
|
nSize—Size of each array element. |
Returns: |
Either a pointer to the array or NULL if the memory couldn’t be |
|
allocated. |
Example: |
int |
*pOurArray; |
pOurArray = calloc(100, sizeof(int));
Note: The calloc() function initializes the memory to zero.
ceil()
Header: |
math.h |
Syntax: |
double ceil(double dValue); |
Description: |
Returns the smallest integer value not less than dValue. |
Parameters: |
dValue—Number for which the ceiling value is desired. |
Returns: |
The integer ceiling value, converted to a double. |
Example: |
dCeil = ceil(-2.2); |
|
/* dCeil will be -2.0 */ |
Note: |
See floor(). |
clearerr()
Header: |
stdio.h |
Syntax: |
void clearerr(FILE * filepointer); |
Description: |
Clears an existing end of file or other error condition for the |
|
given file. |
Part IV • Documenting the Differences
Example: |
dReturned = cos(0.5) |
|
/* dReturned will be 0.877583 */ |
Note: |
When dValue is a large value, the result may not be significant. |
cosh()
Header: |
math.h |
Syntax: |
double cosh(double dValue); |
Description: |
Returns the hyperbolic cosine of dValue (in radians). |
Parameters: |
dValue—Value to compute the hyperbolic cosine of. |
Returns: |
Hyperbolic cosine of dValue. |
Example: |
dReturned = cosh(0.5) |
|
/* dReturned will be 1.1276 */ |
Note: |
When dValue is a large value, the result may not be significant. |
ctime()
Header: |
time.h |
|
Syntax: |
char * ctime(const time_t * TimeBuffer); |
Description: |
Converts the time pointed to by TimeBuffer into a printable |
|
format. |
|
Parameters: |
TimeBuffer—Pointer to a data object of type time_t, properly |
|
initialized (perhaps by using time()). |
Returns: |
Pointer to a character string, which is formatted as the example: |
|
Fri Jun |
26 15:17:00 1992\n\0 |
Example: |
time_t |
OurTime = time(NULL); |
|
printf(ctime(&OurTime); |
Note: |
This function is equal tocallingasctime(localtime(TimeBuffer)). |
Part IV • Documenting the Differences
Example: |
div_t |
DivResult; |
|
DivResult = div(100, 3); |
Note: |
Also see ldiv(). |
exit()
Header: |
process.h & stdlib.h |
Syntax: |
void exit(int nExitCode); |
Description: |
Causes the program to end. |
Parameters: |
nExitCode—An integer passed back to the parent process. |
Returns: |
Does not return. |
Example: |
exit(0); |
Note: |
On MS-DOS systems, only the low order byte of nExitCode is |
|
available. |
exp()
Header: |
math.h |
Syntax: |
double exp(double dValue); |
Description: |
Returns the exponential value of dValue, such that exp(x)=ex. |
Parameters: |
dValue—Value whose exponential value is desired. |
Returns: |
Exponential value of dValue. |
Example: |
double dExp; |
|
dExp = exp(.5); |
|
/* dExp will be 1.6487 */ |
Note: |
An ERANGE error occurs if dValue is too large. |
Part IV • Documenting the Differences
Example: |
int |
nEndOfFile = feof(OpenFile); |
|
|
/* nEndOfFile is zero if not end of |
file */ |
Note: |
Also see clearerr() for clearing the end of file condition. |
ferror()
Header: |
stdio.h |
|
Syntax: |
int ferror(FILE * OpenFile); |
Description: |
Tests for any error conditions for the stream file OpenFile. |
Parameters: |
OpenFile—Pointer to a FILE structure for an opened file. |
Returns: |
A non-zero if there is an error associated with OpenFile. |
Example: |
int |
nError = ferror(OpenFile); |
|
/* nError will be zero if no errors. */ |
Note: |
Also see clearerr() for clearing errors. |
fflush()
Header: |
stdio.h |
|
Syntax: |
int fflush(FILE * OpenFile); |
Description: |
For output files, fflush() writes any unwritten characters in the |
|
file’s buffer to the file. For input files, fflush() will undo the last |
|
ungetc(). If OpenFile is NULL, then all open files are flushed. |
Parameters: |
OpenFile—Pointer to a FILE structure for an opened file or NULL |
|
for all files. |
Returns: |
A non-zero if an error is associated with OpenFile. |
Example: |
int |
nError = fflush(OpenFile); |
|
/* nError is zero if no errors in flushing. |
|
*/ |
|
Note: |
Also see clearerr() for clearing errors. Frequently flushing |
|
output files helps prevent data loss if the computer crashes. |