How to return char (*) [6] in c?

I want to sort an array of strings, which is an array of a character array in c, in alphabetical order. Here is the body of my function: -

char (*)[6] sort_strings ( char (*sptr) [6])
{

     //code.
     //return a pointer of type char (*)[6].

}

But this type of return type is not recognized by the compiler. He gives an error saying: -

expected identifier or '(' before ')' token

So, how do I return a pointer of type char (*) [6]? I have another question: first look main()as follows: -

int main(){

    char names[5][6] = {

            "tom",
            "joe",
            "adam"
    };

    char (*result)[6] = sort_strings (names);

    //code for printing the result goes here.

    return 0;
}

So my next question is that when I call sort strings (names), the compiler also warns me: -

initialization makes a pointer from a whole without cast

So my questions are: -

1. How to return char (*) [6] from a function?

2. Why does the compiler warn me when I call this function?

.

+4
2

, , . :

// asdf is a pointer to an array of 6 chars
char (*asdf)[6];

// sort_strings is a function returning a pointer to an array of 6 chars
// (and with an argument which is a pointer to an array of 6 chars)
char (*sort_strings ( char (*sptr)[6] )) [6];
+10

6 , struct

 struct sixstrings_st {
    char* ptrarr[6];
 };

, , . ( , , ):

 void sort_strings (char**arrptr, unsigned siz);

.

BTW, , qsort (3)

, , , . typedef struct (, union -s).

. ( , , ) ( , ). , ( struct).

C , (, ). struct ( ++, class). struct, , " " ( ). BTW, ABI - struct . x86-64 ABI Linux, struct .

(, malloc ), , , , free . foo_create, struct foo_st ( malloc struct ) foo_destroy, ( , free , struct foo_st*).

, C ( big struct -s, , union -s,...) ( , , C ). , : . , , ( , , )... C ( , , ).

, , 6 . ( ) . , , , . #define MY_WEIRD_SIZE 6 MY_WEIRD_SIZE 6 ...

0

All Articles