Page 99 - Modular_V2.0_C++_Flikpbook
P. 99

In the above code, we have included the iostream.h header file. This allows us to use all the
                 functions defined in iostream.h within our program. A header file can be included using either

                 angle brackets (< >) or double quotes (" ").
                    Angle brackets (< >) instruct the compiler to search for the specified header file in the
                    compiler’s include directory.

                    Double quotes (" ") instruct the compiler to search for the header file in the current directory
                    before looking in the compiler’s include directory.
                 Let us use some of the library functions to understand the concepts better.

                 Functions of ctype.h Header File

                 The ctype.h header file contains the definitions of character handling functions. You need to
                 include this header file in your program to use the character functions. Some of the commonly
                 used functions of the ctype.h header file are:

                  Function Name                            Use                          Example           Output

                 isalpha(char c)      It returns  true  if the  character  c is an  isalpha(‘B’)       True
                                      uppercase or a lowercase letter. Otherwise
                                      returns false.
                 islower(char c)      It returns true if the character c is a lowercase  islower(‘B’)  False
                                      letter. Otherwise returns false.

                 isupper(char c)      It returns  true  if the  character  c is an  isupper(‘B’)       True
                                      uppercase letter. Otherwise returns false.
                 isdigit(char c)      It returns true if the character c is a digit  isdigit(‘9’)      True
                                      from 0 through 9. Otherwise returns false.

                 isalnum(char c)      It returns true if character c is a digit from  isdigit(‘$’)     False
                                      0 through 9 or a letter either uppercase or
                                      lowercase. Otherwise returns false.
                 tolower(char c)      It converts the character c to lowercase if  tlower(‘B’)         b
                                      it  is  in  uppercase.  Nothing  will  change  if
                                      the character is a lowercase letter or a non-

                                      alphabetic character.
                 toupper(char c)      It converts the character c to uppercase if it  toupper(‘b’)     B
                                      is in lowercase. Nothing will change if the
                                      character is an uppercase letter or a non-
                                      alphabetic character.

                 Program 1: To use character handling functions.

                 #include<iostream.h>
                 #include<ctype.h>
                 #include<conio.h>


                                                                                                                  97
                                                                                 Header Files and Library Functions
   94   95   96   97   98   99   100   101   102   103   104