c standard library functions

45
Standard library contains the prepackaged functions which are used while writing a ‘c’ program.

Upload: vaishnavee-sharma

Post on 06-Apr-2017

36 views

Category:

Education


4 download

TRANSCRIPT

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. double acos(double x); 2. double asin(double x); 3. double atan(double x); 4. double atan2(double x ,double y);

5. long double acosl(long double (x)); 6. long double asinl(long double (x)); 7. long double atanl(long double (x)); 8. long double atan2l(long double(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. Long double cos (long double x); 5. Long double sin (long double x); 6. Long double 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