A pointer to a constant `time_t` object, representing time as the number of seconds since the epoch (00:00:00 UTC, January 1, 1970). The data it points to cannot be modified.
1st Parameter
Pointer to a `time_t` object representing the time in seconds since the epoch
2nd Parameter Type : char *
String pointer (array of characters)
2nd Parameter
Pointer to a user-supplied buffer to store the resulting string
Read more about parameters of ctime_r in parameters section
The ctime_rfunction in C language Thread-safe version of ctime.
The ctime_r function is a thread-safe version of ctime. It converts the calendar time pointed to by timer into a string of the form 'Www Mmm dd hh:mm:ss yyyy\n', where Www is the weekday, Mmm is the month in letters, dd is the day of the month, hh:mm:ss is the time, and yyyy is the year. The string is in local time. Unlike ctime, ctime_r stores the result in a user-supplied buffer, making it safe for use in multi-threaded programs.
The ctime_rfunction takes 2
parameters:
•
const time_t * `timer`: Pointer to a `time_t` object representing the time in seconds since the epoch
•
char * `buffer`: Pointer to a user-supplied buffer to store the resulting string
Converts the time value pointed to by `timer` into a human-readable string in the format 'Day Mon DD HH:MM:SS YYYY\n' and writes the result to the user-provided buffer. This is a thread-safe version of `ctime`.
The ctime_r function return value :
Returns a pointer to the string result if successful, or NULL if an error occurred
Output
This example demonstrates the basic usage of the `ctime_r` function. It gets the current time using time() and then converts it to a readable string using ctime_r(), storing the result in a user-provided buffer.