Hi Community of Coders/Programmers,

I am trying to solve a problem having mix of everything, from sorting to using array, to finding length of array. 

I'm trying to figure out median of numbers input in an array of strings, then converted to int array. Even array and odd array both have a different median. 

While dry-running, I enter array as `1,2,3,4,5,6,7` and then press `Enter`. But the result I get is `0`. What could be the error in debugging it, any variable which is left uninitialised? 

Thanks.

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

#define TRUE 1;
#define FALSE 0;

int arrayeven_median(int[], int);
int arrayodd_median(int[], int);
int stringlen(char[]);
int *sort(int[], int);

int num[100];
char numbers[100];
char string[100];
int sortednum[100];

int main()
{
    printf("Enter array of numbers separated by comma\n");

    gets(numbers);

    char *pt;
    /* get the first token */
    pt = strtok(numbers, ",");

    /* walk through other tokens */
    while (pt != NULL)
    {
        int i = 0;
        num[i] = atoi(pt);
        sortednum[i] = *sort(&num[i], stringlen(numbers));
        pt = strtok(NULL, ",");
        i++;
    }

    if (stringlen(numbers) % 2 == 0)
        printf("%d", arrayeven_median(sortednum, stringlen(numbers)));
    else
        printf("%d", arrayodd_median(sortednum, stringlen(numbers)));
    return 0;
}

int stringlen(char string[])
{
    int i;
    for (i = 0; string[i] != '\0'; i++)
        ;
    return i;
}

int *sort(int x[], int n)
{
    int hold, j, pass;
    int switched = TRUE
    ;

    for (pass = 0; pass < n - 1; pass++)
    {
        switched = FALSE
        ;
        for (j = 0; j < n - pass - 1; j++)
            if (x[j] > x[j + 1])
            {
                switched = TRUE
                ;
                hold = x[j];
                x[j] = x[j + 1];
                x[j + 1] = hold;
            }
    }
    return x;
}

int arrayeven_median(int x[], int n)
{
    int m1 = n / 2;
    int m2 = (n / 2) + 1;
    int median = (x[m1] + x[m2]) / 2;
    return median;
}

int arrayodd_median(int x[], int n)
{
    int m1 = (n / 2) + 1;
    int median = x[m1];
    return median;
}

```