Library Functions

1. Character Handling Functions in the Header File ctype.h

a. isalnum: int isalnum (int character) ;

Returns nonzero if character is a digit or a letter; returns 0 otherwise.

b. isalpha: int isalpha (int character) ;

Returns nonzero if character is a letter; returns 0 otherwise.

c. iscntrl:int iscntrl (int character) ;

Returns nonzero if character is a control character; returns 0 otherwise.

d. isdigit:int isdigit (int character) ;

Returns nonzero if character is a digit; returns 0 otherwise.

e. isgraph:int isgraph (int character) ;

Returns nonzero if character is a printing graphic character other than space;

returns 0 otherwise.

f. islower:int islower (int character) ;

Returns nonzero if character is a lowercase letter; returns 0 otherwise.

g. isprint:int isprint (int character) ;

Returns nonzero if character is a printing character including space; returns 0

otherwise.

h. ispunct:int ispunct (int character) ;

Returns nonzero if character is a punctuation character; returns 0 otherwise.

i. isspace:int isspace (int character) ;

Returns nonzero if character is a whitespace character; returns 0 otherwise.

j. isupper:int isupper (int character) ;

Returns nonzero if character is a uppercase letter; returns 0 otherwise.

k. isdigit:int isdigit (int character) ;

Returns nonzero if character is a digit; returns 0 otherwise.

l. tolower:int tolower (int character) ;

Returns character as an lowercase letter if character is a uppercase letter; returns 0

otherwise.

m. toupper: int toupper (int character) ;

Returns character as an uppercase letter if character is a lowercase letter; returns 0

otherwise.

2. Mathematical Functions in the Header File math.h

a. ceol:double ceil (double x) ;

Returns the smallest integer larger than or equal to x.

b. fabs:double fabs (double x) ;

Returns the absolute value of x.

c. floor:double floor (double x) ;

Returns the largest integer smaller than or equal to x.

d. pow:double pow (double x) ;

Returns s raised to the y power; if x is zero, y must be positive, and if x is negative,

y must be an integer.

e. sqrt:double sqrt (double x) ;

Returns the square root of x, where x >= 0.

3. General Utilities in the Header File stdlib.h

a. rand:int rand (void) ;

Returns a random number in the range >0 to less than 32,767 .

b. exit:exit (0) ;

Results in a normal termination.

c. abs:int abs (int x) ;

Returns the absolute value of x.

4. String Functions in the Header File string.h

a. strcat:strcat (string1, string2) ;

Concatenates string2 to the end of string 1.

b. strchr:strchr (string , character) ;

Locates the first occurrence of character in string.

c. strcmp:strcmp (string1, string2) ;

Compares string1 to string2 and returns 0 if equal to, returns less than 0 if less than,

and returns greater than 0 if greater than.

d. strcpy:strcpy (string1, string2) ;

Copies string 2 into string 1.

e. strlen:strlen ( string) ;

Determines the length of a string.

f. strstr:strstr (string1, string2) ;

Locates the first occurrence in string1 of string2.

5. Input-Output Functions in the Header File stdio.h

a. getc:int getc (FILE *Stream) ;

In general, the function getc is equivalent to fgetc; it reads and returns the next

character from the input Stream as an integer and advances the associated read

position for the stream.

b. getchar:int getchar (void) ;

Returns the next character from the standard input stream stdin. If the stream is at

end-of-file or a read error occurs, it returns EOF.

c. putc:int putc (int Character, FILE *Stream) ;

In general, the function putc is equivalent to fputc: it writes Character to the output

Stream at the position indicated by the associated write position, advances the write

position, and returns the character written as an integer. If a write error occurs, it

returns EOF.

d. putchar:int putchar (int Character) ;

Writes Character to the standard output stream stout ar the position indicated by the

associated write position, advances the write position, and returns the character

written as an integer. If a write error occurs, it returns EOF.

6. Date and Time Functions in the Header File time.h

a. clock:clock_t clock (void) ;

Returns the processor time used by the program.

C++ INTERACTIVE INPUT AND OUTPUT FUNCTIONS

1. The Standard Input/Output Stream iostream.h

a. cout < Output Expression ;

The Output Expression can be a constant, a variable, an expression, a function call,

or a manipulator.

The insertion operator, < , is an operator that requires two operands, the standard

output stream cout and an output expression. It takes the value generated by the

output expression and inserts it into the standard output stream cout.

b. cin > InputExpression ;

In C++, cin is the predefined input stream for which the source is the standard input

device (the terminal keyboard).

The extraction operator, > , is a binary operator that requires two operands; the

standard input stream cin and a variable. It extracts a value from the input stream cin

and assigns it to its second operand, the variable.

2. Manipulators for Formatted Output iomanip.h

a. In C++, output formatting can be accompliched using manipulators. A manipulator is a function-

like operator that allows certain formatting operations to be inserted into an output stream. There

are quite a few manipulators in C++. Here, we will study six of them: endl, setw, setfill,

setprecision, setiosflags, and resetiosflags.