According to the task, all month strings start with capital letters!
month Months[12] = {{ 31,"Jan",1}, ...
According to the task, the date should be in the EU format DD-MMM-YYYY. This should also be changed accordingly.
char *c[] = { "24-Jul-2017", "25-Jul-2017", "11-Jun-1996", "01-Jan-2019", "12-Aug-2005", "01-Jan-1997" };
size_t n = sizeof(c) / sizeof(c[0]);
Note: Since the month is to be stored with 3 letters, you need enough space for it if you want to process it as a string in the structure.
It is recommended to write a function for the output to be able to output both the original data and the sorted data.The complete main program then looks like this:
puts("original:");
date_print(c, n);
date_sort(c, n);
puts("sorted:");
date_print(c, n);
To sort data you first need a function that performs the comparison. If it is allowed in C the built in function qsort() is suitable for this.
see:
http://www.cplusplus.com/reference/clibrary/cstdlib/qsort/
Since the data are not well comparable in the existing form it would be perhaps better to create first in an auxiliary structure and assign there a pointer to the original data, as well as an auxiliary variable to be calculated, which can be sorted easily.
Richard had already suggested creating the string as an auxiliary variable in descending order in the form "YYYYMMDD". When I look at the already existing structure for converting the month string, it seems that you should compare and sort possibly days as numbers. In any case, the months must be converted to a sortable format such as a number so that they are sortable just like the year and day.
I suggest to calculate the number of days from each date. But you can also use the date as a string with numbers as suggested by Richard. The pointer to the original date string as well as the calculated helper variable must then each be transferred to the sorthelp auxiliary structure.
The definition of the structure could look like this:
typedef struct {
char* datestr;
unsigned long days;
} sorthelp;
When the number of days has been calculated for all date strings, you can call qsort with it.
sorthelp *sh = malloc(sizeof(sorthelp)*n);
for (size_t i = 0; i < n; i++) {
...
...
}
qsort(sh, n, sizeof(sorthelp), compare);
for (size_t i = 0; i < n; i++) {
...
}
free(sh);
Note: Instead of the auxiliary structure, the conversion and comparison could also be done directly in the compare() function. However, since the comparison might be needed very often for sorting, the performance could suffer a lot. For performance reasons I would rather implement the comparison with a number than with a string.