Jump to content


Question About Strcmpi N String

1 reply to this topic

#1 malayloi



  • Members
  • 2 posts

Posted 11 March 2008 - 01:15 PM

:( i have a question that i need anyone to help me resolve it... please...

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

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

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.

Sample output is given as follows:

Enter each string on a different line:

Type ‘END’ when finished
String 1: Panda
String 2: Apple
String 3: Island
String 4: Calendar
String 5: Brown
String 6: Black
String 7: Rainbow
String 8: News
String 9: Ballroom
String 10: Canada
String 11: END

Reordered list of strings:

String 1: Apple
String 2: Ballroom
String 3: Black
String 4: Brown
String 5: Calendar
String 6: Canada
String 7: Island
String 8: News
String 9: Panda
String 10: Rainbow
String 11: END

#2 D.Cauby



  • EstablishedMember
  • 5 posts
  • Location:United States
  • Interests:Auto racing, motorcross

Posted 07 November 2009 - 06:53 AM

I wonder if the standard specifies that string literals use the datatype char only? If so then that would be a good reason why the literals are narrow unless preceded by L.

Reply to this topic


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users