The goal is a function, that delivers an int (or long) with the actual time. I therefor write the localtime into a string (as far as I understood this) and try to convert it with atoi/atol into my int/long. But somehow I don't get the expected result.
Things I've tried:
- I switched from the initial int to long.
- I changed the size of my string. If I resize it to 7 instead of my needed 15 bytes, it converts at least the date part of my string. But I need it all.
I've got the following code:
long generate_time()
{
time_t time1;
time(&time1);
char time_str[15];
long act_time;
strftime(time_str, 15, "%Y%m%d%H%M%S", localtime(&time1));
printf("Actual time: %s\n", time_str);
act_time = atol(time_str);
printf("Transformed time: %d\n", act_time);
return act_time;
}
Resulting in the response:
Actual time: 20170407091221 Transformed time: 1240669205
I hope this is easy to sort out and thank you all for your help in advance!