### How to create a temp in a 2D Array sort

Hello, I am sorry to bother you guys again, but I'm unsure of how to properly finish up this program. I am unsure of how one is supposed to make a temp for sorting a 2D array.

Once again, this is C++!

Here is the program:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include #include #include void sort(char [][11]); //initializing functrion main() { char state[3][11]; //initializing array char str1[]="Florida"; //initializing needed strings char str2[]="Oregon"; char str3[]="California"; char str4[]="Georgia"; strcpy(state[0], str1); //inserting value of strings into array strcpy(state[1], str2); strcpy(state[2], str3); strcpy(state[3], str4); //sort(state); //calls upon sort function printf("%s\n", state[0]); //prints sorted strings printf("%s\n", state[1]); printf("%s\n", state[2]); printf("%s\n", state[3]); system("PAUSE"); return 0; } void sort (char Str[][11]) { int i; char temp; //for switching out values int flag=1; //true false flag int d=4; //shell sort distance while(flag =1 || d>1) //shell sort function { flag=0; d=(d-1)/2; for(i=0; i<4-d; i++) { if( strcmp(Str[i+d],Str[i])>0) strcpy(temp[0],Str[i+d]); strcpy(Str[i+d],Str[i]); strcpy(Str[i],temp); flag=1; } } return; }``````
I managed to solve the problem on my own! Here is the solution for any who need it. It should be mentioned however that the sort still does'nt work!

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061`` ``````#include #include #include void sort(char [][11]); main() { char state[3][11]; char str1[]="Florida"; char str2[]="Oregon"; char str3[]="California"; char str4[]="Georgia"; strcpy(state[0], str1); strcpy(state[1], str2); strcpy(state[2], str3); strcpy(state[3], str4); //sort(state); printf("%s\n", state[0]); printf("%s\n", state[1]); printf("%s\n", state[2]); printf("%s\n", state[3]); system("PAUSE"); return 0; } void sort (char Str[][11]) { int i; char temp[3][10]; int flag=1; int d=4; while(flag =1 || d>1) { flag=0; d=(d-1)/2; for(i=0; i<4-d; i++) { if( strcmp(Str[i+d],Str[i])>0) { strcpy(temp[0],Str[i+d]); strcpy(Str[i+d],Str[i]); strcpy(Str[i],temp[0]); flag=1; } } } return; } ``````
Topic archived. No new replies allowed.