|
|
Another useful string function is strcmp()
which is used to determine if two strings are identical.
The prototype is:
It returns values of <0, 0 or >0 depending whether
s1 is less than, equal or greater than s2
What does "less than" mean in this context?
A comparison is made on a character by character basis in
each string until the two strings are different. Then the
ordering of the characters in the ASCII characterset (see
Appendix E in King) is used to determine the relative order
of the two strings. Typical usage might be:
if ( strcmp (s1, s2) == 0) {..//strings identical..}
The three functions strlen(), strcpy()and strcmp()are
enough for our purpose. When you need more you will be
skilled enough to read the prototypes in <string.h>
Read King Chapter 13 and K&R Chapter 7 for details
|
|