ANSI STANDARD C FUNCTION DEFINITIONS Version
1.2.5
FOR THE CURIOUS
THE
DESPERATE
THE FRANTIC
AND THE SUICIDAL
Updated 10 April 2005
The material contained in this ebook is not to be altered or
copied without written permission from the author.
Geoffrey Trott ©1998
t_geoffrey@hotmail.com
Useful reference Books
C PRIMA PLUS 4
EDITION by Stephen Prata (C99)
THE STANDARD C LIBRARY by PJ Plauger
(C89)
A B C D E F G I L M O P Q R S T U V W
C89
assert.h ctype.h locale.h math.h setjmp.h signal.h
stdarg.h stddef.h stdio.h stdlib.h string.h time.h
complex.h ctype.h fenv.h inttypes.h math.h stdarg.h
stdio.h stdlib.h string.h time.h wchar.h wctype.h
void abort (void)
HEADER stdlib.h
PURPOSE
This function causes
the program which calls it to end abruptly, unless SIGABRT
is caught and the interrupt handler function defined by signal()
does not return.
RESULT
No values are returned
by this function.
NOTES
Whether files open when
abort() is called are closed, or information contained within buffers
linked to those files transferred, is implementation defined.
abort()
calls raise(SIGABRT),
which returns an implementation defined message confirming unsuccessful
termination to the operating system.
Although ANSI does not require it, many
implementations display an error message of some kind.
int abs (int num)
HEADER stdlib.h
PURPOSE
To convert the value
passed to num into its absolute value.
RESULT
If successful
abs() returns the absolute value of the integer num, otherwise the
value returned is implementation defined.
NOTES
An absolute value can be
any NON negative value including ZERO.
SEE ALSO div(), fabs(), labs(), ldiv(), C99.
double acos (double angle)
HEADER math.h
PURPOSE To convert the double precision value passed to angle into its arc cosine.
RESULT
If successful,
acos() returns the arc cosine of angle in radians, otherwise if
the value returned by acos() is not a double, a range error (an illegal
return value) will occur.
Or if the value is too large to fit inside a
double, acos() returns + or - HUGE_VAL,
in either case errno
is set to ERANGE.
If the value is too small acos() returns 0.0, but whether
errno is set to ERANGE is implementation defined.
NOTES
If the value contained
within angle is neither a double number, nor between -1 and 1.
A
domain error (an illegal argument) will occur, the global integer errno
set to EDOM,
and an implementation defined value returned.
SEE ALSO asin(), atan(), atan2(), cos(), cosh(), sin(), sinh(), tan(), tanh(), C99.
char *asctime (const struct tm *currtime)
HEADER time.h
PURPOSE
To obtain the current
date, in the form of weekday, month, day of the month, hour, minutes, seconds,
year.
This is then placed into a string 26 characters
long.
RESULT
If successful,
asctime() returns a pointer to the buffer where the character string has
been stored,
otherwise the value it returns is implementation defined.
NOTES
Each time either asctime(), or
ctime() is called, information stored within the string
may be overwritten.
To initialise the tm structure pointed to by currtime,
either localtime(), or gmtime() must be called.
The tm structure contains at least the following members in any order:
| int tm_sec | the number of seconds | (0,60) |
| int tm_min | the number of minutes | (0,59) |
| int tm_hour | the number of hours | (0,23) |
| int tm_mday | the day of the month | (1,31) |
| int tm_month | the number of months since January | (0,11) |
| int tm_year | the number of years since 1900 | (0,99) |
| int tm_wday | the number of days since Sunday | (0,6) |
| int tm_yday | the number of days since January 1st | (0,365) |
| int tm_isdst | the daylight savings time indicator |
SEE ALSO clock(), difftime(), time().
double asin (double angle)
HEADER math.h
PURPOSE
To convert the double precision value passed to
angle into its arc sine.
RESULT
If successful, asin() returns the arc sine of angle, in
radians, otherwise if the value returned by asin() is not a double, a
range error (an illegal return value) will occur.
Or if the value is too
large to fit inside a double, asin() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small asin() returns 0.0, but whether
errno is set to ERANGE is implementation defined.
NOTES
If the value contained within angle is neither a double number, nor
between -1 and 1.
A domain error (a illegal argument) will occur, the global
integer errno set to EDOM, and
an implementation defined value returned.
SEE ALSO acos(), atan(), atan2(), cos(), cosh(), sin(), sinh(), tan(), tanh(), C99.
void assert (int comparison)
HEADER assert.h
PURPOSE
To help track down errors of logic within a
program.
RESULT
No values are returned by this function.
NOTES
assert() is implemented as a macro not a function.
If the
assert() macro is replaced by a function, the behavior of that function
is undefined.
If the result of the comparison is ZERO,
assert() generates an implementation defined error message.
Showing
the predefined macros _FILE_ (the name of the file), and _LINE_
(the line where the error occurred),
together with the values contained
within comparison.
Following this it calls abort().
Otherwise assert() will allow the program to continue.
If you
wish to switch assert() off, after the program has been tested for bugs,
#define the macro NDEBUG.
double atan (double angle)
HEADER math.h
PURPOSE
To convert the double precision value passed to
angle into its arc tangent.
RESULT
atan() returns the arc tangent of angle, in radians, otherwise
if the value returned by atan() is not a double, a range error (an
illegal return value) will occur.
Or if the value is too large to fit inside
a double, atan() returns + or - HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small atan() returns 0.0, but whether
errno is set to ERANGE is implementation defined.
NOTES
If the value contained within angle is not a double value, a domain
error (an illegal argument) will occur, the global integer errno set to
EDOM,
and an implementation defined value returned.
SEE ALSO acos(), asin(), atan2(), cos(), cosh(), sin(), sinh(), tan(), tanh(), C99.
double atan2 (double first, double second)
HEADER math.h
PURPOSE
To calculate the value of the arc tangent of
first divided by second, using the signs of both arguments to
calculate its quadrant.
RESULT
If successful, atan2() returns the value of the arc tangent in
radians, otherwise if the value returned by atan2() is not a double, a
range error (an illegal return value) will occur.
Or if the value is too
large to fit inside a double, atan2() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small atan2() returns 0.0, but whether
errno is set to ERANGE is implementation defined.
NOTES
If the values of both first and second do not contain double
precision numbers, or contain ZERO.
A domain error (an illegal
argument) will occur, the global integer errno set to EDOM,
and an implementation defined value returned.
SEE ALSO acos(), asin(), atan(), cos(), cosh(), sin(), sinh(), tan(), tanh(), C99.
int atexit (void(*func)(void))
HEADER stdlib.h
PURPOSE
The function pointed to by func(), will be
called when the program terminates normally.
RESULT
atexit() returns ZERO if the function exists and can be
nominated.
Otherwise a NON ZERO value is returned.
NOTES
ANSI allows a minimum of 32 termination functions to be nominated.
They are called in reverse order by exit(),
these functions cannot have parameters.
SEE ALSO abort(), getenv(), system().
double atof (const char *string)
HEADER stdlib.h
PURPOSE
To convert the character array pointed to by string into a double precision value.
RESULT
If successful, atof() returns a double value.
Otherwise its
behavior is implementation defined, it does not have to change the value of the
global integer errno.
NOTES
If *string does not contain a floating point number, the value
returned cannot be used.
The character array must contain the following in
this order:-
[WHITE SPACE SIGN] INTEGER DECIMAL POINT INTEGER [d,D,e,E
SIGN INTEGER]
A WHITE SPACE consists of an optional space and or a tab character, which are both ignored.
SIGN is either + or -, and is also optional.
INTEGER may contain one or more decimal
numbers.
If no numbers appear before the DECIMAL
POINT then at least one must appear after it.
The numbers may be
followed by an exponent, which consists of an introductory letter, either d,
D, e, or E and an optional signed integer.
The character array will be
processed by atof(), until the function reaches a character which it
doesn't recognize, this includes `\0`.
SEE ALSO atoi(), atol(), strtod(), strtol(), strtoul().
int atoi (const char *string)
HEADER stdlib.h
PURPOSE
To convert the contents of the character array,
pointed to by string into an integer value.
RESULT
If successful, atoi() returns an integer value.
Otherwise its
behavior is implementation defined, it does not have to change the value of the
global integer errno.
NOTES
The character array pointed to by string must contain the following
in this order:-
[WHITE SPACE SIGN] INTEGER
A WHITE SPACE consists of an optional space and or a tab character, which are both ignored.
SIGN is either + or -, and is also optional.
INTEGER may contain one or more decimal
numbers.
The character array is processed by
atoi() until the function reaches a character which it does not recognise
, this includes `\0`.
atoi() does not recognise decimal points or
exponents.
SEE ALSO atof(), atol(), strtod(), strtol(), strtoul().
long int atol (const char *string)
HEADER stdlib.h
PURPOSE
To convert the character array pointed to by
string into a long integer.
RESULT
If atol() returns a long integer.
Otherwise its behavior is
implementation defined, it does not have to change the value of the global
integer errno.
NOTES
The character array pointed to by string must contain a long integer
value, and take the form:-
[WHITE SPACE SIGN] LONG INTEGER
A WHITE SPACE consists of an optional space and or a tab character, which are both ignored.
SIGN is either + or -, and is also optional.
INTEGER may contain one or more decimal numbers.
The character array will then be processed by
atol() until the function reaches a character which it doesn't recognise,
this includes `\0`.
atol() does not recognise decimal points or
exponents.
SEE ALSO atof(), atoi(), strtod(), strtol(), strtoul().
void *bsearch (const void *key1, const void
*buffer, size_t
length, size_t
width,
int
(*compare) (const void *key2, const void *elem))
HEADER stdlib.h
PURPOSE
To perform a binary search on the sorted array
pointed to by buffer, until a match is found with the character pointed
to by key1.
Where length is the number of array elements, and
width the size in bytes of each element.
compare points to a
user defined function, which carries out the actual comparison.
key2
points to the same character pointed to by key1 within bsearch(),
while elem points to an individual element within the sorted
array.
RESULT
If successful, bsearch() itself returns a generic pointer, containing
the address of the first match with *key2, otherwise it returns the macro
NULL (a
NULL pointer).
The user defined function pointed to by compare is
called at least once by bsearch().
Each time (*compare ())
tests the value within the array element pointed to by elem, to check
whether it matches the value pointed to by key2.
It must return one
of the following three values:-
| Less than ZERO | If *key2 is less than *elem |
| ZERO | If *key2 is equal to *elem |
| More than ZERO | If *key2 is greater than *elem |
NOTES
The array being searched must be sorted in ascending order, with the lowest
array element containing the lowest value.
It must not contain duplicate
records with identical keys.
SEE ALSO qsort().
void *calloc (size_t num, size_t length)
HEADER stdlib.h
PURPOSE
To allocate an area of memory for an array of
elements.
Where num is the number of individual elements and
length their size in bytes.
RESULT
If successful, calloc() returns a generic pointer to the beginning of
the area of memory allocated. Otherwise it returns the macro NULL (a
NULL pointer).
NOTES
Unlike malloc(), calloc()initialises all the bits within the
array to ZERO.
double ceil (double upwards)
HEADER math.h
PURPOSE
To calculate the double precision value passed to
upwards, rounded up to its next whole number.
RESULT
If successful ceil() returns a double value, rounded up to the next
whole number, otherwise if the value returned by ceil() is not a double,
a range error (an illegal return value) will occur.
Or if the value is too
large to fit inside a double, ceil() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small ceil() returns 0.0.
When a domain error
occurs, an implementation defined value is returned.
NOTES
If the value contained within upwards is not a double.
A domain error
(an illegal argument) will occur, and the global integer errno set to
EDOM.
SEE ALSO fabs(), floor(), fmod().
void clearerr (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To switch the file error flag off, and to reset the
End Of File indicator associated with the file pointed to
by file_pointer.
RESULT
No values are returned by this function.
SEE ALSO feof(), ferror(), fgetpos(), ftell(), fseek(), fsetpos(), perror(), rewind().
clock_t clock (void)
HEADER time.h
PURPOSE
To find out how long a distinct process within a program has been
running.
RESULT
If successful, clock() returns the amount of time the entire program has
been running, as an variable of type clock_t,
otherwise it returns
(clock_t)-1.
NOTES
To convert the value returned by clock() into seconds divide it by
the macro CLOCKS_PER_SEC.
SEE ALSO asctime(), ctime(), difftime(), gmtime(), localtime(), mktime(), strftime(), time().
double cos (double angle)
HEADER math.h
PURPOSE
To convert the double precision value passed to
angle into its cosine.
RESULT
If successful, cos() returns the cosine of angle, in radians,
otherwise if the value returned by cos() is not a double, a range error
(an illegal return value) will occur.
Or if the value is too large to fit
inside a double, cos() returns + or - HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small cos() returns 0.0, but whether errno
is set to ERANGE is implementation defined.
NOTES
If the value contained within angle is not a double number, a domain
error (an illegal argument) will occur, the global integer errno set to
EDOM, and
an implementation defined value returned.
SEE ALSO acos(), asin(), atan(),atan2(), cosh(), sin(), sinh(), tan(), tanh(), C99.
double cosh (double angle)
HEADER math.h
PURPOSE
To convert the double precision value passed to
angle into its hyperbolic cosine.
RESULT
If successful, cosh() returns the hyperbolic cosine of angle,
in radians, otherwise if the value returned by cosh() is not a double, a
range error (an illegal return value) will occur.
Or if the value is too
large to fit inside a double, cosh() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small cosh() returns 0.0, but whether
errno is set to ERANGE is implementation defined.
NOTES
If the value contained within angle is not a double number, a domain
error (an illegal argument) will occur, the global integer errno set to
EDOM, and
an implementation defined value returned. .
SEE ALSO acos(), asin(), atan(), atan2(), cos(), sin(), sinh(), tan(), tanh(), C99.
char *ctime (const time_t *num_seconds)
HEADER time.h
PURPOSE
To obtain the local time in the form of weekday,
month, day of month, year, hours, minutes, seconds.
Which is placed in a
string 26 characters long.
RESULT
If successful, ctime() returns a pointer to the buffer, where the
character string has been stored, otherwise it returns an implementation defined
value.
NOTES
Before calling ctime() num_seconds, a pointer to the calendar time,
must be obtained by calling time().
The calendar time is stored as a object of type time_t, containing an
implementation defined variable.
Each time either
asctime(), or
ctime()
, is called, information stored within the string may be
overwritten.
SEE ALSO clock(), difftime().
double difftime (time_t end, time_t begin)
HEADER time.h
PURPOSE
To calculate the difference in seconds between the
value passed to end (the end of a period of time), and that passed to
begin (the beginning).
RESULT
If successful, difftime() returns a double precision value,
containing the time difference in seconds.
NOTES
time_t is an object which stores time as an implementation defined
variable.
The values contained within begin and end can be
obtained by calling clock() on two separate occasions.
SEE ALSO asctime(), clock(), ctime(), gmtime(), localtime(), mktime(), strftime(), time().
div_t div (int number, int divider)
HEADER stdlib.h
PURPOSE
To divide the value passed to number, by the
value contained in divider.
RESULT
If successful, div() returns a div_t structure containing both the
quotient, and the remainder of the division as two separate values, otherwise
the value returned is implementation defined..
NOTES
If the value contained in divider is ZERO, the behavior is
implementation defined.
However, many implementations terminate with an
error message.
The div_t structure contains the following members,
although they do not have to appear in that order:
typedef struct
{ int quot;
int rem; }
div_t
div
SEE ALSO abs(), labs(), ldiv()
void exit (int exit_code)
HEADER stdlib.h
PURPOSE
To terminate the program which calls it.
RESULT
No values are returned by this function.
NOTES
exit() can be executed only once within a program.
If the value
passed to exit_code is ZERO or EXIT_SUCCESS then the program has terminated normally, any other
implementation defined value indicates an error of some kind.
The other
macro used by exit_code is EXIT_FALSE
.
When exit() is called any functions nominated by atexit()
will be called in their reverse order.
Any files which are still open will
be closed, after the buffers linked to them have been emptied.
All temporary
files created by tmpfile()
are deleted.
SEE ALSO abort(),
double exp (double num)
HEADER math.h
PURPOSE
To calculate the natural logarithm e, raised
to the power of num.
RESULT
If successful, exp() returns a double precision value containing e to
the power of num, otherwise if the value returned by exp() is not
a double, a range error (an illegal return value) will occur.
Or if the
value is too large to fit inside a double, exp() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small exp() returns 0.0.
When a domain error
occurs, an implementation defined value is returned.
NOTES
If the value contained within num is not a double, a domain error (an
illegal argument) will occur, and the global integer errno set to
EDOM.
double fabs (double num)
HEADER math.h
PURPOSE
To calculate the absolute (e.g positive) value of
num.
RESULT
If successful fabs() returns the absolute value of num as a
double precision number, otherwise if the value returned by fabs() is not
a double, a range error (an illegal return value) will occur.
Or if the
value is too large to fit inside a double, fabs() returns + or
- HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small fabs() returns 0.0.
When a domain error occurs, an implementation defined value is
returned.
NOTES
The absolute value of a number can only be positive.
If the value
contained within num is not a double, a domain error (an illegal
argument) will occur, and the global integer errno set to EDOM.
SEE ALSO abs(), ceil(), floor(), fmod(), labs().
int fclose (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To close the file pointed to by
file_pointer.
RESULT
If successful, fclose() will return ZERO. Otherwise it returns
EOF.
NOTES
Information in the buffer pointed to by file_pointer will be emptied,
and its contents flushed to that particular file.
However, data which is
waiting to be read will be discarded.
SEE ALSO fflush(), fopen(), freopen().
int feof (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To check whether the end of the file pointed to by
file_pointer has been reached.
RESULT
If the The End Of File indicator has been set,
feof() will return NON ZERO .
Otherwise it returns
ZERO.
NOTES
feof() is often used when working with binary files.
Calling
clearerr(), fseek(), fsetpos(),
or rewind()
will clear the EOF
indicator.
int ferror (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To check for read/write errors in the file
pointed to by file_pointer.
RESULT
If an error has been detected ferror() will return NON
ZERO.
NOTES
Those error flags linked to file_pointer will remain set until either
fclose(), rewind(), or clearerr()
are called.
ferror() is often used when checking for errors in binary
files.
int fflush (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To empty the contents of the output buffer, into the
file pointed to by file_pointer.
RESULT
If successful, fflush() returns ZERO, otherwise it returns
EOF.
NOTES
To flush ALL output buffers call fflush(NULL).
If the file has been opened for read/write, a read may not be
followed by a write.
Or vice versa, without first calling either
fflush(), fseek(), fsetpos(),
or rewind().
SEE ALSO fclose(), fopen(), freopen(), setbuf(), setvbuf().
int fgetc (FILE *file_pointer)
HEADER stdio.h
PURPOSE
To obtain the next character from the file pointed
to by file_pointer, and increment the file position indicator.
RESULT
If successful, fgetc() will return the numerical value of the
character read. Otherwise it will return EOF.
NOTES
fgetc() will also return EOF in the event of a read error.
When working with binary files, feof()
must be called, to check that the End Of File position has
been reached, and ferror()
to check for errors.
If the file has been opened for read/write, a
read may not be followed by a write.
Or vice versa, without first calling
either fflush(), fseek(), fsetpos(), or rewind(),
unless EOF was the last character read by fread()
SEE ALSO fgets(), fputc(), fputs(), fwrite(), getc(), getchar(), gets(), putc(), putchar(), puts().
int fgetpos (FILE *file_pointer, fpos_t *position)
HEADER stdio.h
PURPOSE
To obtain the location of the file position
indicator linked to *file_pointer, this value will then be stored in the
area of memory pointed to by position.
RESULT
If successful, fgetpos() will return ZERO, otherwise it
returns NON ZERO storing an implementation defined positive value in the
global integer errno.
NOTES
The information stored in position can be used later by fsetpos()
to return the file position indicator to its former location.
SEE ALSO fflush(), fseek(), ftell(), rewind(), C99 .
char *fgets (char *string, int width, FILE *file_pointer)
HEADER stdio.h
PURPOSE
To read a line of width - 1 number of
characters long into the buffer pointed to by string, from the file
pointed to by file_pointer.
RESULT
If successful, fgets() will return the address of the input buffer,
otherwise it returns the macro NULL (a
NULL pointer).
NOTES
fgets() will continue to read characters until either the '\n' or
EOF
character is received.
If the length of the line of characters is less than
width, the '\n' character will be copied into *string.
At the
end of the string an '\0' character is added.
To check whether an error has
occurred or the EOF character has been reached, either feof() or
ferror()
needs to be called.
SEE ALSO fgetc(), fputc(), fread(), fwrite(), getc(), getchar(), gets(), putc(), putchar(), puts(), C99 .
double floor (double lower)
HEADER math.h
PURPOSE
To round the double precision value passed to
lower, down to its next whole number.
RESULT
If successful floor() returns a double value rounded down to its
nearest whole number, otherwise if the value returned by floor() is not a
double, a range error (an illegal return value) will occur.
Or if the value
is too large to fit inside a double, floor() returns + or -
HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small floor() returns 0.0.
When a domain
error occurs, an implementation defined value is returned.
NOTES
If the value contained within lower is not a double a domain error
(an illegal argument) will occur, and the global integer errno set to
EDOM.
SEE ALSO ceil(), fabs(), fmod().
double fmod (double first, double second)
HEADER math.h
PURPOSE
To calculate the remainder of first divided
by second.
RESULT
If successful fmod() returns a positive double precision value that
is less than the value of second, otherwise if the value returned by
fmod() is not a double, a range error (an illegal return value) will occur.
Or if the value is too large to fit inside a double, fmod() returns
+ or - HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small fmod() returns 0.0.
When a domain error
occurs, an implementation defined value is returned.
NOTES
If the values of both first and second do not contain double
precision numbers, a domain error (an illegal argument) will
occur, and the global integer errno set to EDOM.
If the value of second is ZERO, whether a domain error occurs
or fmod() returns 0.0 is implementation defined.
SEE ALSO ceil(), fabs(), floor().
FILE *fopen (const char *file_name, const char *mode)
HEADER stdio.h
PURPOSE
To open the file, whose name is pointed to by
file_name, where mode points to the type of access
allowed.
RESULT
If successful, fopen() returns a pointer to the opened file.
Otherwise it returns the macro NULL
(a NULL pointer).
NOTES
Unless the length of *file_name is implementation defined, FILENAME_MAX will be the recommended size of the array.
The macro
FOPEN_MAX
determines the number of files that a program may have open at the same time,
under MSDOS this will be at least eight.
Since three are always
assigned to stdin (standard input), stdout (standard output), and
stderr (standard error), that leaves five.
However, these three can
if necessary be reassigned using freopen().
If the file has been opened for read/write, a read may not be
followed by a write.
Or vice versa, without first calling either
fflush(), fseek(), fsetpos(), or rewind().
Unless EOF was
the last character read by fread().
The parameter pointed to by mode must contain one of the following
values:
| "a" | Open a text file for writing, create one if it does not already exist, append to the bottom of the file. |
| "a+" | Open a text file for reading and writing, create one if it does not already exist, append to the bottom of the file. |
| "ab" | Open a binary file for writing, create one if it does not already exist, append to the bottom of a file. |
| "ab+" | Open a binary file for reading and writing, create one if it does not already exist, append to the bottom of the file. |
| "r" | Open a text file, if it already exists for reading |
| "r+" | Open a text file, for reading and writing, if it already exists erase the contents. |
| "rb" | Open a binary file, if it already exists for reading. |
| "rb+" | Open a binary file, for reading and writing, if it already exists erase the contents. |
| "w" | Open a text file for writing, if it already exists erase the contents, otherwise create one. |
| "w+" | Open a text file for reading and writing, if it already exists erase the contents. |
| "wb" | Open a binary file for writing, if it already exists erase the contents. |
| "wb+" | Open a binary file for reading and writing, if it already exists erase the contents. |
SEE ALSO fclose(), ftell(), fgetpos(), C99 .
int fprintf (FILE *file_pointer, const char *format, [argument], ...)
HEADER stdio.h
PURPOSE
To write a series of alphanumeric or printable
characters to the file pointed to by file_pointer.
Where
format points to the type of alphanumeric or printable character or
characters, which will be contained in argument, and '...'
indicates a variable number of arguments.
RESULT
If successful, fprintf returns the number of characters that
have been written to the file, otherwise a negative value is returned.
A
minimum of 509 characters can be written at any one time.
NOTES
The rules that apply to *format are the same as for printf().
SEE ALSO fscanf(), scanf(), sprintf(), sscanf(), vfprintf(), vprintf(), vsprintf() C99
int fputc (int ch, FILE *file_pointer)
HEADER stdio.h
PURPOSE
To write a character to the file pointed to by
file_pointer, and increment its file position indicator.
RESULT
If successful, fputc() returns a positive value corresponding to the
character written, otherwise it returns EOF.
NOTES
This function performs the same action as putc().
However, fputc() is more likely to be a function, not a macro.
Use ferror()
to check whether an error has occurred.
The value passed to ch is
converted by fputc() into an unsigned char.
If no file position
indicator exists, the character is appended to the end of the file.
SEE ALSO fgetc(), fgets(), fputs(), getc(), getchar(), gets(), putchar(), puts(), ungetc().
int fputs (const char *string, FILE *file_pointer)
HEADER stdio.h
PURPOSE
To write the character array pointed to by
string, into the file pointed to by file_pointer.
RESULT
If successful, fputs() returns a positive value. Otherwise it returns
EOF.
NOTES
An '\n' character at the end of the string will not be written to the
file.
SEE ALSO fgetc(), fgets(), fputc(), getc(), getchar(), gets(), putc(), putchar(), puts(), ungetc(), C99 .
size_t fread (void *buffer, size_t width, size_t count, FILE *file_pointer)
HEADER stdio.h
PURPOSE
To read a group or groups of variables from a file
pointed to by file_pointer, into the array pointed to by buffer.
Where count is the number of groups is to be read, and width
their length in bytes.
RESULT
If successful, fread() returns the number of groups read, and
increments the file position indicator, otherwise it returns
ZERO.
NOTES
If the file pointed to by file_pointer is in text mode, all carriage
return line feed characters will be replaced by single line feed characters.
If the file has been opened for read/write, a read may not be
followed by a write, or vice versa, without first calling either
fflush(), fseek(), fsetpos(),or rewind().
Unless EOF was
the last character read by fread().
SEE ALSO fwrite(), fgetpos(), ftell(), C99 .
void free (void *memory_ptr)
HEADER stdlib.h
PURPOSE
To free an area of memory.
RESULT
No values are returned by this function.
NOTES
Before calling free() the area of memory pointed to by
memory_ptr, must have been assigned by calling either calloc(), malloc(), or realloc().
If the value contained in memory_ptr is the value NULL (a NULL
pointer) no action occurs.
FILE *freopen (const char *new_file, const char *mode, FILE *file_pointer)
HEADER stdio.h
PURPOSE
To close the file, whose name is pointed to by
file_pointer, which is then reassigned to another file.
Where
new_file points to the name of the new file, and mode the file access
mode.
RESULT
If successful, freopen() returns the address of the new file,
otherwise it returns the macro NULL
(a NULL pointer).
NOTES
Unless the length of *new_file is implementation defined,
FILENAME_MAX will be the recommended size of the array.
See fopen()
for a complete description of *mode.
freopen() can be used to
redirect stderr (standard error device), stdin (standard input
device), and stdout (standard output device), to files on disk or to
other devices.
freopen() clears the error and end of file indicators,
linked to file_pointer.
SEE ALSO fclose(), fflush(), setbuf(), setvbuf(), C99 .
double frexp (double num, int *exp)
HEADER math.h
PURPOSE
To convert the value passed to num into its
mantissa,within the range of 0.5 to 0.999.
RESULT
If successful frexp() returns the mantissa of num, and stores
the exponent in the integer pointed to by exp, otherwise if the value
returned by frexp() is not a double, a range error (an illegal return
value) will occur.
Or if the value is too large to fit inside a
double,frexp() returns + or - HUGE_VAL,
in either case errno is
set to ERANGE.
If the value is too small, or num equals ZERO,
frexp() returns 0.0.
When a domain error occurs, an
implementation defined value is returned.
NOTES
If the values passed to frexp are not, a double precision number and
an integer, in that order.
A domain error (an illegal argument) will result,
and the global integer errno set to EDOM.
If num contains ZERO, frexp() will return ZERO, and
store ZERO in *exp.
SEE ALSO exp(), ldexp(), log(), log10(), modf().
int fscanf (FILE *file_pointer, const char *format, [argument],...)
HEADER stdio.h
PURPOSE
To read information from the file pointed to by
file_pointer, into the areas of memory specified by argument.
Where argument contains the addresses of those memory areas, *format
describes the type of alphanumeric or printable characters contained in
argument, and '... 'indicates a variable number of arguments.
RESULT
If is successful, fscanf() returns the number of groups of variables
that have been read.
Otherwise it returns EOF
in the case of an error, or ZERO if none were read.
To
check whether the EOF character has been reached, call either feof() or
ferror().
NOTES
See scanf()
for a complete description of *format.
SEE ALSO