C 从二维数组到双指针的转换

C 从二维数组到双指针的转换,c,arrays,pointers,C,Arrays,Pointers,我正在尝试将2d数组转换为双指针,我在stackoverflow上找到了一个解决方案,但它不起作用,如果我进行打印,它只是胡言乱语 我必须这样做,因为我以后调用的函数需要一个常量字符**,我无法更改它 void test(const char** sl, int n) { char s[n][20], t[20]; int i, j, a; for(i = 0; i < n; ++i) { strcpy(s[i], sl[i]); } f

我正在尝试将2d数组转换为双指针,我在stackoverflow上找到了一个解决方案,但它不起作用,如果我进行打印,它只是胡言乱语

我必须这样做,因为我以后调用的函数需要一个常量字符**,我无法更改它

void test(const char** sl, int n) {

   char s[n][20], t[20];
   int i, j, a;

   for(i = 0; i < n; ++i) {
       strcpy(s[i], sl[i]);
   }


   for (i = 1; i < n; i++) {
      for (j = 1; j < n; j++) {
         if (strverscmp(s[j - 1], s[j]) > 0) {
            strcpy(t, s[j - 1]);
            strcpy(s[j - 1], s[j]);
            strcpy(s[j], t);
         }
      }
   }

   char *solutionPtrs[n];
   for (a = 1; a < n; a++)
           solutionPtrs[n] = s[n];

   char **ptr = solutionPtrs;


   printf("\nStrings in order are : ");
   for (i = 0; i < n; i++)
      printf("\n%s", ptr[i]); <-- just not what it should be.

}
无效测试(常量字符**sl,int n){
字符s[n][20],t[20];
int i,j,a;
对于(i=0;i0){
strcpy(t,s[j-1]);
strcpy(s[j-1],s[j]);
strcpy(s[j],t);
}
}
}
char*solutionPtrs[n];
对于(a=1;aprintf(“\n%s”,ptr[i]);我认为这里有一个错误:

for (a = 1; a < n; a++)
        solutionPtrs[n] = s[n];
(a=1;a 溶液ptrs[n]=s[n];
你是说:

for (a = 0; a < n; a++)
        solutionPtrs[a] = s[a];
(a=0;a 溶液ptrs[a]=s[a];