#This is a homework assignment#
I need to calculate how many seconds old I am in C. I'm thinking that I can take my birthday as user input and convert it to a date with strptime. I then would like to take the present date and put both it and my birthday into seconds or unix time. Then it's just a matter of subtraction to get the right output. The code below takes the command line parameters: mm dd yyyy, puts them(I think) attempts to convert it to a date recognized by the tm_structure and then print it. It fails with the output Your Birthday is: (null) Any input on how to fix this would be of great help. Also, any suggestions if there is a more efficient way to do this would also be of great help.
Thanks
P.S. I'm a beginner
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
int main(int argc, char *argv[]) {
char *month, *day, *year;
char buf[256];
int result;
struct tm *tm_ptr;
time_t the_time;
month = argv[1];
day = argv[2];
year = argv[3];
strcpy(buf, month);
strcat(buf, " ");
strcat(buf, day);
strcat(buf, " ");
strcat(buf, year);
result = strptime(buf,"Today is %m %d %Y.\n", the_time);
printf("Your Birthday is: %s\n", result);
(void) time(&the_time);
tm_ptr = gmtime(&the_time);
printf("Current time in seconds is: %ld\n", the_time);
return 0;
}