- 论坛徽章:
- 0
|
我实验这两各函数不知道为什么没有输出,请指教。
代码如下:
- #include <time.h>;
- #include <stdio.h>;
- #include <string.h>;
- #include <strings.h>;
- #include <locale.h>;
- int main(void)
- {
- struct tm tm1;
- time_t t;
- char *sp;
- char buf[1024];
- tm1.tm_sec=10;
- tm1.tm_min=20;
- tm1.tm_hour=10;
- tm1.tm_mon=9;
- tm1.tm_mday=21;
- tm1.tm_year=2001-1900;
- memset(buf,0,1024);
- t=mktime(&tm1);
- memcpy(&tm1,localtime(&t),sizeof(struct tm));
- /*strcpy(buf,"1999/06/08010101");*/
- sp=strptime(buf,"%m/%d/%y",&tm1);
- printf("tm1.tm_year = [%d]\n",tm1.tm_year);
- printf("tm1.tm_mon = [%d]\n",tm1.tm_mon);
- printf("tm1.tm_mday= [%d]\n",tm1.tm_mday);
- /*sp=strptime(buf,"[%a] [%A] [%b] [%B] [%c] [%C] \n [%d] [%D] [%e] [%h]
- [%H] \n [%I] [%j] [%m] [%M] [%n] [%p] \n [%r] [%R] [%S] [%t] [%T] [%U] \n [%w] [
- %W] [%x] [%X] [%y] [%Y] \n [%%] [%Ec] [%EC] [%Ex] [%EX] [%Ey] [%EY] [%Od] \n [%O
- e] [%OH] [%OI] [%Om] [%OM] \n [%OS] [%OU] [%Ow] [%Oy]",&tm1);*/ /* 原先的格式 */
- printf("buf = { [%s] }\n",buf);
- printf("sp = { [%s] }\n",sp);
- }
复制代码
结果:
tm1.tm_year = [101]
tm1.tm_mon = [9]
tm1.tm_mday= [21]
buf = { [] }
sp = { [] }
buf和sp中什么也没有,tm中数据也没有变化,请问这两各函数是如何使用的???? |
|