Pr.Pg Next Pg

C and C++ Pre-Defined Functions tutorials

Function

Type

Prototype and Description

Header File

abort ( )

 

void abort ( );

Aborts the program

<stdlib.h>

abs ( )

int

int abs ( int n;)

Return the absolute value o f n

<stdlib.h>

acos ( )

double

double acos (double x);

Returns the inverse cosine (arcsine) of x

<math.h>

asin ( )

double

double asin (double x);

Returns the inverse tangent (arctangent) of x

<math.h>

atan ( )

double

double atan (double x )

Returns th e inverse tangent (arctangent)of x

<math.h>

atof ( )

double

double atof (const char* s);

Returns the floating-poinmt number represented literally in the string s

<stdlib.h>

atoi ( )

int

int atoi (const char * s);

Returns the integer represented literally in the string s.

<stdlib.h>

atol ( )

long

long atol (const char* s);

Return the integer represended literally in the string s.

<stdlib.h>

bad ( )

 

int ios : :bad ( );

Returns nonzero if badbit is set;returns 0 otherwise

<iostream.h>

bsearch ( )

 

void* bsearch (const void* x, void* a

size_t n,

size_t s,

int (*cmp)

(const void*,const void*));

Implementation the binary search algorithm to search for x in the sorted array a of n elements each of size s using the function *cmp to compare any two such elements. If found a pointer to the element is returned; otherwise, the NULL pointer is returned.

<stdlib.h>

ceil ( )

double

Double ceil (double x );

Returns x rounded upto the next whole number.

<math.h>

clear ( )

 

void ios : :clear (int n=0);

Changes stream state to n.

<iostream.h>

 

 

Void clearer (FIFLE* P)

Clears the end of life and error flags for the file *p

<stdio.h>

close ( )

 

void fstreambase : : close ( );

closes the file attatched to the owner object

<fstream.h>

cos ( )

double

double cos (double x);

Returns the inverse cosine of x.

<math.h>

cosh ( )

double

Double cosh (double x);

Returns the hyperbolic cosine of x: (ex+e-x)/2.

<math.h>

difftime ( )

double

double difftime (time_t t1,time_t t0);

Returns time elapsed (in seconds) from time t0 to time t1.

<math.h>

eof ( )

 

int ios : :eof ( );

Returns nonzero if eofbit is set: returns 0 otherwise

<iostream.h>

exit ( )

void

void exit( int n);

Terminates the program and returns n to thr invoking process.

<stdlib.h>

 

exp ( )

double

double exp (double x);

Returns the exponential of x: ex.

<math.h>

fabs ( )

double

double fabs (double x);

Returns the absolute value of x.

<math.h>

fail ( )

 

int ios : :fail ( );

Return nonzero if failbit is set; returns 0 otherwise.

<iostream.h>

fclose ( )

int

int fclose (FILE* p);

Close the file *p and flushes all buffers. Returns 0 if successful;

returns EOF otherwise.

<stdio.h>

fgetc ( )

int

char*fgets(char*s, int n, File*p);

Read the next line from the file *p and stores int in it *s.The “next line” means either the next n-1 characters or all the characters up to the next endline character,whichever comes first. The NUL character is appended the characters stored in s.Returns s if successful; return NULL otherwise

<stdio.h>

fill ( )

 

char ios : : fill ( );

Return the current fill character.

char ios : : fill (char c);

Changes the current fill character to c and returns the previous fill character.

<iostream.h>

flags ( )

 

long ios : : flags ( );

Returns the current fill character.

long ios flags (long n);

Changes the current format flags to n; returns the previous flags.

<iostream.h>

floor ( )

double

double floor (double x);

Return x rounded down to the next whole number.

<math.h>

flush ( )

 

Ostream & ostream : : flush ( );

Flushes the output buffer and returns the updates stream.

<iostream.h>

fopen ( )

file*

FILE* fopen(const char* p, const char* s);

Opens the file *p and returns the address of the structure that represents the file if successful; returns NULL otherwise.The string s determines the file’s mode: “r” for read, “w” for write “a” for append, “r+” for reading and writing an existing file, and “a+” for reading and appending an existing file.

<stdio.h>

fprintf ( )

int

int fprintf (FILE *p, const char* s, … );

Writes formatted output to the file *p. Returns the number character printed if successful; otherwise it returns a negative number.

<stdio.h>

fputc ( )

int

int fputc ( int c, FILE *p);

Writes character c to the file *p. Returns a character written or EOF if unsuccessful.

<stdio.h>

 

fputs ( )

int

int fputs (const char *s, FILE *p);

Write string s to the file *p. Returns a nonnegative integer if successful; otherwise it returns EOF

<stdio.h>

 

fread ( )

int

size_t fread ( void*s, size_t k, size_t n, FILE* p);

Reads up to n items each of size k from the file *p and stores them at location s in memory. Returns the number of items read.

<stdio.h>

 

fscanf ( )

int

int fsacnf ( FILE* p, const char * s, … );

Reads formatted input from the file *p and stores them at location s in memory. Returns EOF if end of file is reached; otherwise it returns the number of items read into the memory.

<stdio.h>

 

fseek ( )

int

int fseek ( FILE* p, long k, int base);

Repositions the positions marker of the file * p k bytes from its base, where base should be SEEK_SET for the beginning of the file, SEEK_CUR fo the current positions of the file marker, or SEEK_END for the end of the file. Returns 0 if successful.

<stdio.h>

 

ftell ( )

long int

long ftell ( FILE *p);

Returns the location of the position marker in file *p or returns -1.

<stdio.h>

 

fwrite ( )

int

size_t fwrite (void*s, size_t k, size_t n, FILE* p);

Writes n items each of size k to the file *p and returns the number written.

<stdio.h>

 

gcount ( )

 

int stream : : gcount ( );

Returns the number of characters most recently read.

<iostream.h>

get ( )

 

int istream : :get ( );

istream & istream : : get (signed char & c);

istream & istream : : get (unsigned char &c);

istream & istream : : get (signed char* b,int n, char e = ’\n’);

istream & istream : : get (unsigned char* b, int n, char e = ‘\n’);

Reads the next character c from the istream. The first version returns c or EOF. The last two versions read upto n characters into n characters into b, stopping when e is encountered.

<iostream.h>

getc ( )

int

int getc (FILE* p );

Same as fgetc ( ) except implemented as a macro.

<stdio.h>

getchar ( )

int

int getchar ( );

Returns the next character from the standard input or returns EOF.

<stdio.h>

gets ( )

char*

char* gets(char* s);

Read next line from standard input and stores it in s. Returns s or NULL if no characters are read.

<stdio.h>

good ( )

 

int ios : : ()’

Returns nonzero if stream state is zero;returns zero otherwise.

<iostream.h>

ignore ( )

 

Istream & ignore (int n=1, int e = EOF);

Extracts up to n characters from stream, or up to the character e, whichever comes first. Returns the stream.

<iostream.h>

isalnum ( )

int

int isalnum (int c);

Returns nonzero if c is an alphabetic or numeric character; returns0 otherwise.

<ctype.h>

isalpha ( )

int

int isalpha (int c);

Returns nonzero if c is an alphabetic character or returns0.

<ctype.h>

iscntrl ( )

int

int iscntrl (int c);

Returns nonzero if c is a control character; otherwise returns0

<ctype.h>

isdigit ( )

int

int isdigit (int c);

Returns nonzero if c is any non blank printing character; otherwise returns0

<ctype.h>

isprint ( )

int

int islower (int c);

Returns nonzero if c is any printing character; otherwise returns0.

<ctype.h>

 

ispunct ( )

int

int ispunct (int c);

Returns nonzero if c is any punctuation mark,except the alphabetic characters, the numberic characters and the blank; otherwise returns 0.

<ctype.h>

isspace ( )

int

int isspace (int c);

Returns nonzero if c is any white space character,including the blank ‘ ‘;the form feed ’\f’, the newline ‘\n’, the carriage return ‘\r’, the horizontal tab ‘\t’, and the vertical tab ;\v’;

Otherwise returns 0;

<ctype.h>

isupper

int

int isupper (int c);

Returns nonzero if c is an uppercase alphabetic character; otherwise return 0;

<ctype.h>

isxdigit ( )

int

int isdigit (int c);

Returns nonzero if c is one of the digit characters or one of the 12 hexadecimal digit letters: ‘a’, ; ‘b’, ‘c’, ‘d’, ‘e’, ‘f’,.

‘A’, ‘B’, ‘C’, ‘D’, ‘E’, or ‘F’ ;otherwise returns 0.

<ctype.h>

labs ( )

long labs

long labs (long n);

Return absolute value of n.

<ctype.h>

log ( )

double

double log (double x);

Return the natural logarithm (base e) of x.

<math. h>

log10 ( )

double

double log10 (double x);

Returns the common logarithm (base 10) of x.

<math. h>

membchr ( )

 

void* memchr(const void* s, int c, size_t k);

Searches the k bytes of memory beginning at s for character c. If found, the address of its first occurrence is returned.Returns NULL otherwise.

<string.h>

memcmp ( )

 

int memchp (const void* s1, const void* s2,size_t k);

Compares the k bytes of of memory beginning at s1 with k bytes of memory beginning at s2 and returns a negative , zero or a positive. integer according whether the first string is lexicographically less than, equal to, or greater than the second string.

<string.h>

memcpy ( )

 

void* memcmp (const void* s1, const void* s2, size_t k);

Copies the k bytes of memory beginning at s2 into memory beginning at s2 into memory location s1 and returns s1

<string.h>

Memmove ( )

 

int mmemove (const void* s1, const s2, size_t k);

same as memcpy ( ) except strings may overlap.

<string.h>

open ( )

 

void fstream : : open (const char* f, int m,

int p=filebuf : :openprot);

void ifstream : : open (const char* f,

int m = ios : :in,

int p = filebuf :: openprot);

void ofstrem : : open ( const char* f,

int m =ios : : out,

int p=filebuf : :openprot);

void ofstream : : open ( const char* f,

int m=ios: : out,

int p=filebuf : : openprot);

Opens the file f in mode m with protection p.

<fstream.h>

peek ( )

 

int istream : : peek ( );

Returns next character (or EOF)from stream without extracting it.

<iostream.h>

pow ( )

double

double pow (double x, doub;e y);

Returns x raised to the power y (xy).

<math.h>

precision ( )

 

int ios : : precision ( );

int ios : : precision (int k);

Returns the current precision for the stream.The second version changes the current precision to k and returns the old precision.

<iostream.h>

 

tolower ( )

int

int tolower (int c);

Returns the lowercase version of c if c is uppercase alphabetic character; otherwise returns c.

<ctype.h>

toupper ( )

int

int toupper (int c);

Return the uppercase version of c if c is a lowercase alphabetic character; otherwise returns c.

<ctype.h>

 

Pr.Pg border                                              Next Pg