asctime.c
来自「标准c库代码,可以应用于各个系统提供了大量的基本函数」· C语言 代码 · 共 93 行
C
93 行
/* * asctime.c * Original Author: G. Haley * * Converts the broken down time in the structure pointed to by tim_p into a * string of the form * * Wed Jun 15 11:38:07 1988\n\0 * * Returns a pointer to the string. *//*FUNCTION<<asctime>>---format time as stringINDEX asctimeINDEX _asctime_rANSI_SYNOPSIS #include <time.h> char *asctime(const struct tm *<[timp]>); #include <time.h> char *_asctime_r(const struct tm *<[timp]>, void *<[reent]>);TRAD_SYNOPSIS #include <time.h> char *asctime(<[timp]>) struct tm *<[timp]>; #include <time.h> char *_asctime_r(<[timp]>, <[reent]>) struct tm *<[timp]>; char *<[reent]>;DESCRIPTIONFormat the time value at <[timp]> into a string of the form. Wed Jun 15 11:38:07 1988\n\0The string is generated in a static buffer; each call to <<asctime>>overwrites the string generated by previous calls.<<_asctime_r>> provides the same function as <<asctime>>, but isreentrant. The extra argument <[reent]> is a pointer to a reentrancystructure.RETURNSA pointer to the string containing a formatted timestamp.PORTABILITYANSI C requires <<asctime>>.<<asctime>> requires no supporting OS subroutines.*/#include <stdio.h>#include <time.h>#include <reent.h>char *_DEFUN (_asctime_r, (tim_p, data), _CONST struct tm *tim_p _AND void *data){ static _CONST char day_name[7][3] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static _CONST char mon_name[12][3] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; struct _reent *p = data; sprintf (p->_asctime, "%.3s %.3s %.2d %.2d:%.2d:%.2d %d\n", day_name[tim_p->tm_wday], mon_name[tim_p->tm_mon], tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min, tim_p->tm_sec, 1900 + tim_p->tm_year); return p->_asctime;}#ifndef _REENT_ONLYchar *_DEFUN (asctime, (tim_p), _CONST struct tm *tim_p){ return _asctime_r (tim_p, _REENT);}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?