HP C/iX Library Reference Manual (30026-90004)

Chapter 5 105
HP C/iX Library Function Descriptions
asctime
asctime
Converts a tm structured time variable into a null-terminated 26-character string.
Syntax
#include <time.h>
char *asctime (const struct tm *
timeptr
);
Parameters
timeptr
A pointer to a structure of type tm that contains the broken-down time.
Return Values
x A pointer to the string.
Description
The asctime function provides a way for you to get the current time, modify it in some
way, and then print the result in ASCII form.
The
timeptr
parameter points to a structure of type tm whose members were assigned
values with localtime(), gmtime(), or explicitly by you. The asctime function returns a
character pointer to a null terminated string with a maximum length of 26 characters.
This string is the same type as the string returned by ctime(). Because asctime()
returns a pointer to a static character array, it is overwritten by subsequent calls to
asctime().
Example
The date command shown in the section on ctime() can be rewritten using localtime()
and asctime():
#include <stdio.h>
#include <time.h>
main()
{
int time(), nseconds;
struct tm *ptr, *localtime();
char *string, *asctime();
nseconds = time(NULL);
/* you may modify the current time in tm here */
string = asctime(ptr);
printf("%s", string);
}
This program illustrates an indirect way to obtain the date, but it does enable you to