Question: I'm a newbie with C language and I need to make a function to sort an array of struct Student data types (after the element `Student.ime` alphabetically). I am not really sure where to put the pointers so I can return the new array.

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Student {
    int id;
    char ime[20];
    char prezime[20];
    char brindexa[20];
    struct Datum datum_rodjenja;
};

struct Student sortiraj(struct Student niz[], int vel)
{
    int i, j;
    struct Student tempo;
    tempo = niz[0];
    for(j=0 ; j<vel ; j++)
    {
        for(i=j ; i<vel ; i++)
        {
            if(strcmp(tempo.ime,niz[i].ime)>0)
            {
                tempo = niz[i];
            }
            i++;
        }
        niz[j] = tempo;
        j++;
    }
    return niz;
}

```

The array is stored in a `.txt` file but that is not the problem. One more thing, how do I call the function in the `main()`. I thought maybe like this?

```
niz=sortiraj(niz, vel);

```

Can someone give me any tips please. Thank you.

Answer: 
Have you considered using the `qsort()` function? Example: 

If you have an array of strings say *strings*, (Note: not an array of structs), with the number of strings being say, *cnt* then: 

```
qsort(strings, cnt, sizeof(char*), sortstring);  

```

With the function sortstring defined as: 

```
static int sortstring( const void *str1, const void *str2 )
{
    const char *rec1 = *(const char**)str1;
    const char *rec2 = *(const char**)str2;
    int val = strcmp(rec1, rec2);

    return val;
}

//for a simple test, run this main with the code above:  

int main(void)  
{  
    char *strings[]={"this", "is", "a", "test", "of", "the", "qsort", "function", "to", "try"};
    int strlen = sizeof(strings)/sizeof(char *);

    qsort(strings, strlen, sizeof(char *), sortstring);

    return 0;
}  

//Note my environment required #include <ansi_c.h>

```
Since you are passing in a pointer, namely `niz`, you are changing the memory that `niz` points to. This means that you don't *have* to return `niz`. 

However if you want to return `niz` your function's return type must be the same type as `niz`. Currently you have a return type of just `struct Student` so you should be getting a compilation error.