Solved

Using String ToUpper, Sorting an Array of string without CaseSensitive

Posted on 2003-10-23
7
571 Views
Last Modified: 2010-04-01
I need to sort an array of string where I don't want the Capitals to be smaller then the normal case.

Example A = a

I guess using ToUpper will help me but I can't get it to work.
Or maybe there is another way to do it .

Thank you
0
Comment
Question by:sly_06
  • 4
7 Comments
 

Author Comment

by:sly_06
ID: 9606998
Here is what I got so far ,
It display the list not even in Order

void Sort(string LIST[],string TYPE[],int n)
{

 string tmp;
 
 char TEMP[2000][200];
 string TEMP2[2000];
 for (int i = 0 ; i < n ; i++)
            {
            strcpy(TEMP[i],LIST[i].c_str());
                  int j = 0;
                  do
                  {
                        if(TEMP[i][j] >= 97 && TEMP[i][j] <= 122 )
                              TEMP[i][j] -= 32;
                              j++;
                  }while(TEMP[i][j]!=0);
                  TEMP2[i] = TEMP[i];
            }

            
            for (int i = 0 ; i < n ; i++)
      
      //This is for Debugging Purposes      
      cout << TEMP2[i] << " " << TEMP[i]<< LIST[i] << endl;
 
 for (int i=0; i<n-1; i++) {
  for (int j=0; j<n-1-i; j++){
    //this is to be able to find repeated words since , I dont want repetition
    if (LIST[j+1] == LIST[j]){
    LIST[j] = "";
    TYPE[j] = "";
    }//End of IF
    else if (TEMP2[j+1] < TEMP2[j]) {  /* compare the two neighbors */
      tmp = LIST[j];           /* swap a[j] and a[j+1]      */
      LIST[j] = LIST[j+1];
      LIST[j+1] = tmp;
      tmp = TYPE[j];           /* swap a[j] and a[j+1]      */
      TYPE[j] = TYPE[j+1];
      TYPE[j+1] = tmp;
  }//End Of ElseIF
  }//End of Inner For Loop
}//End of Outer For Loop


}//End Of Sort Function
0
 
LVL 2

Expert Comment

by:federal102
ID: 9607378
Do you need to preserve the original capitalization after sorting and do you need to remove duplicates?
0
 

Author Comment

by:sly_06
ID: 9607465
yes, well I created 2 function, void SORT and void SORTWITHOUTREMOVE

and I need to keep the original Case after , this is why Im doing the check on the TEMP2 but affecting the actual LIST.

0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:sly_06
ID: 9608237
Ok I found the problem , I was doing the check on TEMP2 but  I wasnt  swapping in TEMP2.

Is there a way to remove my question ?

SInce I got the aswer (for the points).
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9608843
0
 

Accepted Solution

by:
sly_06 earned 0 total points
ID: 9610717
void Sort(string LIST[],string TYPE[],int n)
{

 string tmp;
 
 char TEMP[2000][200];
 string TEMP2[2000];
 for (int i = 0 ; i < n ; i++)
            {
            strcpy(TEMP[i],LIST[i].c_str());
                  int j = 0;
                  do
                  {
                        if(TEMP[i][j] >= 97 && TEMP[i][j] <= 122 )
                              TEMP[i][j] -= 32;
                              j++;
                  }while(TEMP[i][j]!=0);
                  TEMP2[i] = TEMP[i];
            }

 
 for (int i=0; i<n-1; i++) {
  for (int j=0; j<n-1-i; j++){
    if (TEMP2[j+1] == TEMP2[j]){
            //cout << "False" << endl;
    LIST[j] = "";
    TYPE[j] = "";
      TEMP2[j] = "";

    }//End of IF
    else if (TEMP2[j+1] < TEMP2[j]) {  /* compare the two neighbors */
            //cout << "True" << endl;
      tmp = LIST[j];           /* swap a[j] and a[j+1]      */
      LIST[j] = LIST[j+1];
      LIST[j+1] = tmp;
        tmp = TEMP2[j];           /* swap a[j] and a[j+1]      */
        TEMP2[j] = TEMP2[j+1];
      TEMP2[j+1] = tmp;
      tmp = TYPE[j];           /* swap a[j] and a[j+1]      */
      TYPE[j] = TYPE[j+1];
      TYPE[j+1] = tmp;
  }//End Of ElseIF
  }//End of Inner For Loop
}//End of Outer For Loop
 
}//End Of Sort Function
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 230
C++ assignment question 7 237
C++ error cannot convert from std::string to const char * 6 250
object oriented programming comparison 5 77
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question