ordering Character array

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  for(int i=0;i<NoCand;i++) 
       {for(int j=i+1;j<NoCand;j++) 
        {
       if(NumVotes[j]>NumVotes[i]) {
	            char temp_LastName = LastName[i];
	            float temp_NumVotes = NumVotes[i];
	            LastName[i] = LastName[j];
	            NumVotes[i] = NumVotes[j];
	            LastName[j] = temp_LastName;
	            NumVotes[j] = temp_NumVotes;
	        }
	    }
I'm attempting to use this algorithm to rearrange my character array so that it's in order with my NumVotes value. However it will not allow me to assign the char to char. 
I know this works with strings but for the purpose of this I'm not allowed to use strings. 
	   
Show how is LastName defined?
I am guessing that your LastName array is an array of strings. Is it?

In that case you should declare temp_LastName as char*.

Edit: sorry above will not work because you cannot sssign char arrays like pointers. You will probably have to swap using function like strcpy () or some other function to manipulate c strings. I'm not much conversant with them.
Last edited on
No LastName is declared

char LastName [5] [20]
You have to use standard function std::strcpy declared in header <cstring> in this case. For example

char temp_LastName[20];

std::strcpy( temp_LastName, LastName[i] );
std::strcpy( LastName[i], LastName[j]; );
std::strcpy( LastName[j], temp_LastName; );
Topic archived. No new replies allowed.