void string_sort(char** arr,const int len,int (*cmp_func)(const char* a, const char* b)){
for(int i = 1; i < len; i++){
int j = i;
char* p = arr[i];
while(j > 0){
if((*cmp_func)(arr[j-1],p) > 0 )
arr[j] = arr[j-1];
else
break;
j--;
}
arr[j] = p;
}
}
Assignment with array type (on the left) is not allowed. But assigning array type (on the right) is fine. Consider the following program :
void basic_version (char* a, char* b) {
a = b;
}
int main () {
char a[] = "negla"
char b[] = "pandey_adm"
basic_version (a, b);
return;
}
Note that char*
has no problems with assignment (on either side).
To put it concisely : there are no string/char [] involved in string_sort
. Its just char pointers
and pointers to them.
1 Like