KEMBAR78
C standard library functions | PDF
Standard library contains the
prepackaged functions which are used
while writing a ‘c’ program.
 This header file contains a number of pre-
defined/ library functions which performs
various mathematical calculations.
 To include math.h header file in program use
preprocessor directive-
#include< math.h >
 Modulus function calculates the remainder of
the division operation.
 In ‘c’ modulus function is applied on integer
numbers only by default.
 To apply modulus to floating point values we
use fmod , fmod l ,modf , modf l.
 Modf / modf l splits double/ long double
number into integer and fractional part
respectively.
 It stores the integer in ipart and returns the
fraction.
•Declaration :-
•Fmod , fmod l :-
double fmod (double x , double y);
long double fmod l(long double (x) , long double (y))
•Modf , modf l :-
double modf (double x , double *(ipart));
long double modf l(long double (x) , long double
*(ipart));
ARC FUNCTIONS
SIMPLE
FUNCTIONS
 acos
 asin
 atan
 atan2
 acosl
 asinl
 atanl
 atn2l
 cos
 sin
 tan
Declarations :-
• Real :-
1. doubleacos(double x);
2. doubleasin(double x);
3. doubleatan(double x);
4. doubleatan2(double x ,double y);
5. long double acosl(longdouble (x));
6. long double asinl(longdouble (x));
7. long double atanl(longdouble (x));
8. longdouble atan2l(longdouble(x), long double (y));
• Complex :-
1. Complex acos(complex x);
2. Complex asin(complex x);
3. complex atan(complex x);
Declarations :-
•Real :-
1. Double cos (double x);
2. Double sin (double x);
3. Double tan (double x);
4. Longdouble cos (long double x);
5. Longdouble sin (long double x);
6. Longdouble tan (long double x);
• Complex :-
1. Complex cos (complex x);
2. Complex sin (complex x);
3. complex tan (complex x);
 cosh
 sinh
 tanh
 coshl
 sinhl
 tanhl
Declarations :-
• Real :-
1. Double cosh (double x );
2. Double sinh (double x);
3. Double tanh (double x);
4. Long double coshl (long double x);
5. Long double sinhl (long double x);
6. Long double tanh (long double x);
• Complex :-
1. Complex cosh (complex x);
2. Complex sinh (complex x);
3. Complex tanh (complex x);
power function calculates the power of an input
number.
Syntax :-
power( base , exponent);
TO CALCULATE
POWER OF A
‘DESIRED’ NUMBER
TO CALCULATE
POWER OF ‘10’
 pow
 powl
 Pow10
 Pow10 l
Declaration :-
•Power :-
1. Double pow (double n , double p );
2. Long double pow (long double (n) , long double (p
3. Complex pow (complex n , complex p);
4. Complex pow (double n , complex p);
5. Complex pow (complex n , double p);
• Power10 :-
1. Double pow10 (int p);
2. Long double pow10 (int (p));
 Floor function rounds the value down.
 Floor returns integer found as double.
 Floorl returns integer found as long double.
 Declaration :-
double floor (double x);
long double floorl(long double (x));
 Ceiling function rounds up a number.
 Ceil returns an integer found as double.
 Ceill returns an integer found as long double.
Declaration :-
double ceil (double x);
long double ceil (long double (x));
 Exponential function is used to calculate the
powers of ‘e’.
 For Real numbers ‘e’ raised to power ‘x’ is
calculated.
 For complex numbers ‘e’ raised to power ‘z’ is
calculated (z is a complex number).
Declaration :-
• Real :-
1. double exp(double x);
2. long double exp (long double (x));
•Complex :-
1. complex exp(complex (z));
 square root function is used to calculate the
square root of a given number.
 Declaration :-
 Real :-
double sqrt (double x);
long double sqrt (long double (x));
 Complex :-
complex sqrt (complex x);
 absolute value function returns only the numerical
value without any sign.
 There are different types of abs function :-
o abs (a macro) finds absolute value of an integer .
o fabs , fabs l (macros) finds absolute values of
floating point values.
o Cabs , cabs l finds absolute values for complex
numbers.
o labs finds absolute values for long double values.
•Declaration :-
•abs :-
Real - int abs (int x);
Complex - complex abs (complex z);
•Fabs , fabd l :-
double fabs (double x);
long double fabs (long double @E(x));
•Cabs , cabd l :-
double cabs (struct_complex z);
long double cabd l (struct_complexl z);
•Labs :-
long int labs(long int x);
 This header file contains prepackaged
functions to perform various operations on
‘characters’.
 To include this header file in the program use
the preprocessor directive-
# include < ctype.h >
 toupper is a function which converts lowercase
characters to uppercase characters. If the input
character is already uppercase character then
those characters remain unchanged.
 _toupper is a macro which also converts
lowercase characters to uppercase characters.
But if the input characters have uppercase
characters in it then the result of _toupper is
‘undefined’.
•Declarations :-
1. int toupper (char ch);
2. Int _toupper (char ch);
 tolower is a function which converts uppercase
characters to lowercase characters. If the input
character is already lowercase character then
those characters remain unchanged.
 _tolower is a macro which also converts
uppercase characters to lowercase characters.
But if the input characters have lowercase
characters in it then the result of _tolower is
‘undefined’.
•Declarations :-
1. int tolower (char ch);
2. Int _tolower (char ch);
 Isspace checks it out whether an input
character is a space , tab , carriage return , new
line , vertical tab , or formfeed or not.
 It is a macro and returns a non-zero value on
success.
 Declaration :-
int isspace ( int c );
 The lower order byte of character is in the
range 0 to 127.
 It is a macro and returns a non-zero value on
success.
 Declaration :-
int isascii (int c);
 Isprint checks it out whether the input
character is a printing character or not.
 It is also a macro and returns a non-zero value
on success.
 Declaration :-
int isprint (int c);
 Isgraph checks it out whether input character is
a printing character or not like isprint except
that space character is excluded.
 It is also a macro &returns non-zero value on
success.
 Declaration :-
int isgraph (int c);
 iscntrl checks it whether the input character is a
delete character or an ordinary control
character .
 It is also a macro &returns non-zero value on
success.
 Declaration :-
int iscntrl ( int c);
 isxdigit checks out whether the input character
is a hexadecimal digit or not ( A to F , a to f , 0
to 9).
 It is also a macro &returns non-zero value on
success.
 Declaration :-
int isxdigit (int c);
 To include this header file in the program use
the preprocessor directive-
# include < stdlib.h >
 Abnormally terminates a process & writes a
termination message on stderr(“abnormal
program termination “) and then aborts the
program by a call to _exit with exit code 3.
 Declaration :-
void abort (void);
 atof converts a sting to floating point value .
 _atold converts a string to long double.
 Declaration :-
double atof (const char *s);
long double _atold (const char *(s));
 It is a macro that converts the string to integer.
 Declaration :-
int atoi (const char *s);
 Swab function copies nbytes from the “from”
string to the “to” string .nbytes should be even
.
 Adjacent even &odd bytes are swapped.
 This is useful for moving data from one
machine to another machine in different bytes
order.
 Declaration :-
void swab(char *from, char *to, int nbytes);
 System invokes the DOS command interpreter
file from inside an executing ‘c’ program to
execute a DOS command ,batch file , or other
program named by the string “command”.
 Declaration :-
int system (const char *command);
 time.h header file contains various functions
operating on time .
 Like clock, ctime, stime, time, difftime, acstime,
mktime, gmtime, localtime, etc.
 To include this header file in the program use
preprocessor directive-
# include < time.h >
 Clock returns the number of clock ticks since
program start.
 Clock can be used to determine the time
interval between two events.
 Declaration :-
clock_t clock (void);
 Asctime converts date and time to ascii.
 Ctime converts date and time to a string.
 Declaration :-
char *acstime (const struct tm *tblock);
char *ctime (const time_t *time);
 mktime converts time to calendar format .
 Declaration :-
time_t mktime (struct tm *t);
 time gets time of day.
 stime gets system date and time.
 Declaration :-
time_t time (time_t *timer );
int stime (time_t *tp);
 Difftime computes difference between 2 times.
 Declaration :-
double difftime(time_t time2,time_t time1);
 Gmtime converts date and time to Greenwich
Mean Time (GMT).
 Localtime converts date and time to a structure.
 Declaration :-
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
MADE BY :-
VAISHNAVEE SHARMA

C standard library functions

  • 1.
    Standard library containsthe prepackaged functions which are used while writing a ‘c’ program.
  • 2.
     This headerfile contains a number of pre- defined/ library functions which performs various mathematical calculations.  To include math.h header file in program use preprocessor directive- #include< math.h >
  • 3.
     Modulus functioncalculates the remainder of the division operation.  In ‘c’ modulus function is applied on integer numbers only by default.  To apply modulus to floating point values we use fmod , fmod l ,modf , modf l.  Modf / modf l splits double/ long double number into integer and fractional part respectively.  It stores the integer in ipart and returns the fraction.
  • 4.
    •Declaration :- •Fmod ,fmod l :- double fmod (double x , double y); long double fmod l(long double (x) , long double (y)) •Modf , modf l :- double modf (double x , double *(ipart)); long double modf l(long double (x) , long double *(ipart));
  • 5.
    ARC FUNCTIONS SIMPLE FUNCTIONS  acos asin  atan  atan2  acosl  asinl  atanl  atn2l  cos  sin  tan
  • 6.
    Declarations :- • Real:- 1. doubleacos(double x); 2. doubleasin(double x); 3. doubleatan(double x); 4. doubleatan2(double x ,double y); 5. long double acosl(longdouble (x)); 6. long double asinl(longdouble (x)); 7. long double atanl(longdouble (x)); 8. longdouble atan2l(longdouble(x), long double (y)); • Complex :- 1. Complex acos(complex x); 2. Complex asin(complex x); 3. complex atan(complex x);
  • 7.
    Declarations :- •Real :- 1.Double cos (double x); 2. Double sin (double x); 3. Double tan (double x); 4. Longdouble cos (long double x); 5. Longdouble sin (long double x); 6. Longdouble tan (long double x); • Complex :- 1. Complex cos (complex x); 2. Complex sin (complex x); 3. complex tan (complex x);
  • 8.
     cosh  sinh tanh  coshl  sinhl  tanhl
  • 9.
    Declarations :- • Real:- 1. Double cosh (double x ); 2. Double sinh (double x); 3. Double tanh (double x); 4. Long double coshl (long double x); 5. Long double sinhl (long double x); 6. Long double tanh (long double x); • Complex :- 1. Complex cosh (complex x); 2. Complex sinh (complex x); 3. Complex tanh (complex x);
  • 10.
    power function calculatesthe power of an input number. Syntax :- power( base , exponent);
  • 11.
    TO CALCULATE POWER OFA ‘DESIRED’ NUMBER TO CALCULATE POWER OF ‘10’  pow  powl  Pow10  Pow10 l
  • 12.
    Declaration :- •Power :- 1.Double pow (double n , double p ); 2. Long double pow (long double (n) , long double (p 3. Complex pow (complex n , complex p); 4. Complex pow (double n , complex p); 5. Complex pow (complex n , double p); • Power10 :- 1. Double pow10 (int p); 2. Long double pow10 (int (p));
  • 13.
     Floor functionrounds the value down.  Floor returns integer found as double.  Floorl returns integer found as long double.  Declaration :- double floor (double x); long double floorl(long double (x));
  • 14.
     Ceiling functionrounds up a number.  Ceil returns an integer found as double.  Ceill returns an integer found as long double. Declaration :- double ceil (double x); long double ceil (long double (x));
  • 15.
     Exponential functionis used to calculate the powers of ‘e’.  For Real numbers ‘e’ raised to power ‘x’ is calculated.  For complex numbers ‘e’ raised to power ‘z’ is calculated (z is a complex number).
  • 16.
    Declaration :- • Real:- 1. double exp(double x); 2. long double exp (long double (x)); •Complex :- 1. complex exp(complex (z));
  • 17.
     square rootfunction is used to calculate the square root of a given number.  Declaration :-  Real :- double sqrt (double x); long double sqrt (long double (x));  Complex :- complex sqrt (complex x);
  • 18.
     absolute valuefunction returns only the numerical value without any sign.  There are different types of abs function :- o abs (a macro) finds absolute value of an integer . o fabs , fabs l (macros) finds absolute values of floating point values. o Cabs , cabs l finds absolute values for complex numbers. o labs finds absolute values for long double values.
  • 19.
    •Declaration :- •abs :- Real- int abs (int x); Complex - complex abs (complex z); •Fabs , fabd l :- double fabs (double x); long double fabs (long double @E(x)); •Cabs , cabd l :- double cabs (struct_complex z); long double cabd l (struct_complexl z); •Labs :- long int labs(long int x);
  • 20.
     This headerfile contains prepackaged functions to perform various operations on ‘characters’.  To include this header file in the program use the preprocessor directive- # include < ctype.h >
  • 21.
     toupper isa function which converts lowercase characters to uppercase characters. If the input character is already uppercase character then those characters remain unchanged.  _toupper is a macro which also converts lowercase characters to uppercase characters. But if the input characters have uppercase characters in it then the result of _toupper is ‘undefined’.
  • 22.
    •Declarations :- 1. inttoupper (char ch); 2. Int _toupper (char ch);
  • 23.
     tolower isa function which converts uppercase characters to lowercase characters. If the input character is already lowercase character then those characters remain unchanged.  _tolower is a macro which also converts uppercase characters to lowercase characters. But if the input characters have lowercase characters in it then the result of _tolower is ‘undefined’.
  • 24.
    •Declarations :- 1. inttolower (char ch); 2. Int _tolower (char ch);
  • 25.
     Isspace checksit out whether an input character is a space , tab , carriage return , new line , vertical tab , or formfeed or not.  It is a macro and returns a non-zero value on success.  Declaration :- int isspace ( int c );
  • 26.
     The lowerorder byte of character is in the range 0 to 127.  It is a macro and returns a non-zero value on success.  Declaration :- int isascii (int c);
  • 27.
     Isprint checksit out whether the input character is a printing character or not.  It is also a macro and returns a non-zero value on success.  Declaration :- int isprint (int c);
  • 28.
     Isgraph checksit out whether input character is a printing character or not like isprint except that space character is excluded.  It is also a macro &returns non-zero value on success.  Declaration :- int isgraph (int c);
  • 29.
     iscntrl checksit whether the input character is a delete character or an ordinary control character .  It is also a macro &returns non-zero value on success.  Declaration :- int iscntrl ( int c);
  • 30.
     isxdigit checksout whether the input character is a hexadecimal digit or not ( A to F , a to f , 0 to 9).  It is also a macro &returns non-zero value on success.  Declaration :- int isxdigit (int c);
  • 31.
     To includethis header file in the program use the preprocessor directive- # include < stdlib.h >
  • 32.
     Abnormally terminatesa process & writes a termination message on stderr(“abnormal program termination “) and then aborts the program by a call to _exit with exit code 3.  Declaration :- void abort (void);
  • 33.
     atof convertsa sting to floating point value .  _atold converts a string to long double.  Declaration :- double atof (const char *s); long double _atold (const char *(s));
  • 34.
     It isa macro that converts the string to integer.  Declaration :- int atoi (const char *s);
  • 35.
     Swab functioncopies nbytes from the “from” string to the “to” string .nbytes should be even .  Adjacent even &odd bytes are swapped.  This is useful for moving data from one machine to another machine in different bytes order.  Declaration :- void swab(char *from, char *to, int nbytes);
  • 36.
     System invokesthe DOS command interpreter file from inside an executing ‘c’ program to execute a DOS command ,batch file , or other program named by the string “command”.  Declaration :- int system (const char *command);
  • 37.
     time.h headerfile contains various functions operating on time .  Like clock, ctime, stime, time, difftime, acstime, mktime, gmtime, localtime, etc.  To include this header file in the program use preprocessor directive- # include < time.h >
  • 38.
     Clock returnsthe number of clock ticks since program start.  Clock can be used to determine the time interval between two events.  Declaration :- clock_t clock (void);
  • 39.
     Asctime convertsdate and time to ascii.  Ctime converts date and time to a string.  Declaration :- char *acstime (const struct tm *tblock); char *ctime (const time_t *time);
  • 40.
     mktime convertstime to calendar format .  Declaration :- time_t mktime (struct tm *t);
  • 41.
     time getstime of day.  stime gets system date and time.  Declaration :- time_t time (time_t *timer ); int stime (time_t *tp);
  • 42.
     Difftime computesdifference between 2 times.  Declaration :- double difftime(time_t time2,time_t time1);
  • 43.
     Gmtime convertsdate and time to Greenwich Mean Time (GMT).  Localtime converts date and time to a structure.  Declaration :- struct tm *gmtime(const time_t *timer); struct tm *localtime(const time_t *timer);
  • 45.