Assume that you are required to enter a list of strings into a computer, rearrange them
in alphabetical order, and then print out the rearranged list. The strings must be stored
in a two-dimensional character array. Each string will be stored in a separate row
within the array. You may use any suitable string manipulation functions. One of the
library functions that can be used is strcmpi.
strcmpi compares the strings but does not differentiates between upper and
lowercase characters. The function accepts two strings as arguments and returns
integer value, depending on the relative order of the two strings, as follows:
a) A negative value is returned if the first string alphabetically precedes the second
string.
b) A value of zero is returned if the first string and the second string are identical.
c) A positive value is returned if the second string alphabetically precedes the first
string.
If the function strcmpi (string1, string2) returns a positive value then, this
indicates that string2 must be placed ahead of string1 in order to rearrange the
two strings in alphabetical order.
6
Sample output is given as follows:
Enter each string on a different line:
Type 鈥楨ND鈥?when finished
String 1: Panda
String 2: Apple
String 3: Island
String 4: Calendar
String 5: Brown
String 6: Black
No comments:
Post a Comment