C language provides many functions to manipulate strings. To understand
the functions, let’s consider building block (or unit) of a string
i.e., a character. Characters are represented inside the computers in
terms of numbers. There is a code number for each character, used by a
computer. Mostly the computers use ASCII (American Standard Code for Information
Interchange) code for a character to store it. This is used in the computer
memory for manipulation. It is used as an output in the form of character.
We can write a program to see the ASCII values. We have a data type char
to store a character. A character includes every thing, which we can type
with a keyboard for example white space, comma, full stop and colon etc
all are characters. 0, 1, 2 are also characters. Though, as numbers, they
are treated differently, yet they are typed as characters. Another data
type is called as int, which stores whole numbers. As we know that characters
are stored inside computer as numbers so these can be manipulated in the
same form. A character is stored in the memory in one byte i.e. 8 bits.
It means that 28 (256) different combinations for different values can
be stored. We want to ascertain what number it stores, when we press a
key on the board. In other
In the program the statement c = i ; has integer value on right hand side (as i is an int) while c has its character representation. We display the value of i and c. It shows us the characters and their integer values.
//This program displays the ASCII
int i, char c ;
In the output of this program, we will see integer numbers and their character representation. For example, there is a character, say white space (which we use between two words). It is a non-printable character and leaves a space. From the ASCII table, we can see that the values of a-z and A-Z are continuos. We can get the value of an alphabet letter by adding 1 to the value of its previous letter. So what we need to remember as a baseline is the value of ‘a’ and ‘A’.
Character Handling Functions
C language provides many functions to perform useful tests and manipulations
of character data. These functions are found in the header file ctype.h.
The programs that have character manipulation or tests on character data
must have included this header file to avoid a compiler error. Each function
in ctype.h receives a character (an int ) or EOF (end of file; it is a
special character) as an argument. ctype.h has many functions, which have
self-explanatory names. Of these, int isdigit (int c) takes a simple character
as its argument and returns true or false. This function is like a question
being asked. The question can be described whether it is a character digit?
The answer may be true or false. If the argument is a numeric character
(digit), then this function will return true otherwise false. This is
a useful function to test the input. To check for an alphabet (i.e. a-z),
the function isalpha can be used. isalpha will return true for alphabet
a-z for small and capital letters. Other than
The functions tolower and toupper are conversion functions. The tolower function converts its uppercase letter argument into a lowercase letter. If its argument is other than uppercase letter, it returns the argument unchanged. Similarly the toupper function converts its lowercase letter argument into uppercase letter. If its argument is other than lowercase letter, it returns the argument without effecting any change.