A pointer to a character pointer array... can't pass
I was working on another thread and here's what I came up with:
Code:
#include <stdio.h>
#include <string.h>
typedef char** char1;
typedef char1 *cptr;
void str_swap(char** str1, char** str2);
void bubble_sort(cptr array,int length)
{
int i, j,s;
bool flag = 1;
char* tmp;
int arrayLength = length;
for(i = 0; (i < arrayLength) && flag; i++)
{
flag = 0;
for (j=0; j < (arrayLength -1); j++)
{
s = strcmp(*array[j+1],*array[j]);
if(s>0)//string 2 is greater
{
str_swap(array[j+1],array[j]);
}
}
}
}
int main()
{
char* str1= "Alfred";
char* str2 = "Albert";
char* strs[] = {str1,str2,"Linux","Penguin","Lorraine","Lucas"};
int len = 6;
for(int j=0;j<len;j++)
printf("%s ",strs[j]);
printf("\n");
bubble_sort(&strs,len);
for(j=0;j<len;j++)
printf("%s ",strs[j]);
printf("\n");
return 0;
}
void str_swap(char** str1, char** str2)
{
char* tmp;
tmp = *str1;
*str1 = *str2;
*str2=tmp;
}
but it says cannot convert char(*)(*)[6] to char***
I can't understand why it can't convert it. And do you know of a way I can pass the array of strings into the function and be able to MODIFY that array?
-LC