I have this code that returns the day of the week from the date, for example, "29-02-2016", but sometimes it gives me a segmentation error in localtime (& t).
int obterDiaSemana(char *str) {
struct tm tm2;
if(strptime(str, "%d-%m-%Y", &tm2) != NULL) {
time_t t = mktime(&tm2);
return localtime(&t)->tm_wday;
}
return -1;
}
function gets:
char userDate[10]="29-02-2016";
I was looking for a solution, but I can not solve it.
Thanks in advance.
If you need more information, just let me know.
source
share