The headings you use are non-standard. Use functions from the standard:
#include <time.h> struct tm *localtime_r(const time_t *timep, struct tm *result);
After calling the function above, you can get a working day:
tm->tm_wday
Check out the tutorial / example .
Here is additional documentation with examples here .
As others have pointed out, you can use strftime to get the name of the day of the week when you have tm . Here is a good example here :
#include <time.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char outstr[200]; time_t t; struct tm *tmp; t = time(NULL); tmp = localtime(&t); if (tmp == NULL) { perror("localtime"); exit(EXIT_FAILURE); } if (strftime(outstr, sizeof(outstr), "%A", tmp) == 0) { fprintf(stderr, "strftime returned 0"); exit(EXIT_FAILURE); } printf("Result string is \"%s\"\n", outstr); exit(EXIT_SUCCESS); }
bstpierre
source share