免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1486 | 回复: 3
打印 上一主题 下一主题

help: In my c code ,I can`t use time funtion [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-30 08:56 |只看该作者 |倒序浏览
#include <time.h>
int main(int argc, char *argv[])
{  char strt[150];
   time_t  tp;
  char str;
  time(&tp); ////////////appear error  
  str=ctime(&tp);
}
ERROR:
main.c:37: called object is not a function ,why ?

if using gettimeofday function,how can I chage struct timeval to narmal  string ?
//int gettimeofday(struct timeval *tv,struct timezone*tz)

论坛徽章:
0
2 [报告]
发表于 2006-05-30 14:49 |只看该作者
hi brother!
your code is wrong!
plaese see  here(right code):

#include <time.h>
int main(int argc, char *argv[])
{  char strt[150];
   time_t  tp;
  char *str;
  time(&tp);
  str=strt;
  str=ctime(&tp);
  printf("time is %s",str);
}

you must get basic technique of coding!

呵呵,英语太差了,寒自己一个!

[ 本帖最后由 hubenhua1998 于 2006-5-30 15:14 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2006-05-30 15:05 |只看该作者
不好意思,出现疏忽,不过依然不能用time函数呀

论坛徽章:
0
4 [报告]
发表于 2006-05-30 15:24 |只看该作者

获得字符串格式的系统时间

char SYSTEMTIME[15];
char *getsystemtime()
{
  time_t timer;
  struct tm *tblock;

  memset(SYSTEMTIME,0,sizeof(SYSTEMTIME));
  timer=time(NULL);
  tblock=localtime(&timer);
  sprintf(SYSTEMTIME,"%04d%02d%02d%02d%02d%02d",tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday,tblock->tm_hour,tblock->tm_min,tblock->tm_sec);
  return SYSTEMTIME;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP