Thursday, July 30, 2009

Can someone help debug this part of my C Basic program?

//Alphabetization of Multi-Dim string//


void bubblesort(char *R[], int a); //function declaration//





char *restname[20][30]; //Variable in main//





bubblesort(restname[30], 20);//Function bubblesort in main//





void bubblesort(char *R[], int a)//function bubble sort//


{ int i, j; char *hold;


for(i= 0; i %26lt; a; i++)


{ for(j=0; j%26lt;a-1; j++)


{ if(R[j] %26lt; R[j+1])


{ hold = R[j];


R[j] = R[j+1];


R[j+1] = hold;}


}


}


for(i=0; i%26lt;a; i++)


{ printf("%s", R[i]);


printf("\n"); }


} //end function//





This is for my CSE 1320 programming class


I cant figure out how to get the NEW restname multi-dimensional string to print in alphabetical order! I also cannot use any C,Basic built-in sort functions for this project AND i HAVE to use the sort function using pointers


Can somebody PLEASE help me?


If more info is needed, let me know... but i cant post the program in its entirity due to its length exceeding this text box's character limit


Thanks

Can someone help debug this part of my C Basic program?
I get the point. Your program is in descending order. So, you wish to arrange the characters alphabetically in descending order. The program will give you a syntax error because you cannot have a pointer that can also act as an array. Within the arguments of the bubblesort, there is a declared variable "*R[]" of character type. You can have "*R" or "R[]" but not "*R[]".





Bubble sort deals its elements individually, so I think it's better to use "%c" than "%s"





The main part that confuses me much is that you declared a 2-dimensional array to be passed in the arguments of bubblesort but in the bubble sort arguments you placed a 1-dimensional array and its size. If that is what is passed to the arguments then the entire program is logically erroneous because it only applies to a one-dimensional array.


No comments:

Post a Comment