|
|
|
|
|
|
|
char word1[6] = "Small";
char word2[6] = "Small"; |
|
|
|
|
|
|
|
|
the following function calls would return the results indicated. |
|
|
|
|
| Function Call | Function Value | | | strcmp(word1, word2) | | (They are equal.) | | strcmp(word1, "Tree") | Negative number | | | strcmp("Smile", word1) | Positive number | ('i' comes after 'a'.) | | strcmp("S", word1) | Negative number | ('\0' comes before 'm'.) |
|
|
|
|
|
|
The preceding results would be the same with any character set. Different character sets give different results, however, if an uppercase letter and a lowercase letter are compared. Uppercase letters come before lowercase letters in ASCII and after lowercase letters in EBCDIC. Also, special symbols, such as punctuation marks, are ordered differently with respect to each other in the two sets. |
|
|
|
|
|
|
|
|
We have described only three of the string-handling routines provided by the standard library. These three are the most commonly needed, but there are many more. If you are designing programs that use strings extensively, you should read the documentation on strings for your C++ system. |
|
|
|
|
|
|
|
|
Using Typedef with Arrays |
|
|
|
|
|
|
|
|
In Chapter 10, we discussed the Typedef statement as a way of giving an additional name to an existing data type. The most familiar example is |
|
|
|
|
|
|
|
|
We can also use Typedef to give a name to an array type. Here's an example: |
|
|
|
|
|
|
|
|
typedef float FloatArr[100]; |
|
|
|
|
|
|
|
|
This statement says that the type FloatArr is the same as the type "100-element array of float." (Notice that the array size in brackets comes at the very end of the statement.) We can now declare variables to be of type FloatArr: |
|
|
|
|
|
|
|
|
FloatArr angle;
FloatArr velocity; |
|
|
|
|
|
|
|
|
The compiler essentially translates these declarations into |
|
|
|
|
|