简单的视见函数,令人发疯的问题

l999358 2008-10-30 08:45:54
我用的是Ubuntu操作系统,使用GCC编译.
如下代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

clock_t s;

int main(int argc, char** argv)
{
again:
printf ("now is : %ld\n", s); //clock_t 是 long类型
sleep (1);
goto again;
return 0;
}

但是输出结果是:
now is : 0
now is : 0
now is : 0
now is : 0
now is : 0
now is : 0

怎么回事呀?
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zark 2008-10-30
  • 打赏
  • 举报
回复
没有问题啊,全局变量s初始化为0,然后就是个无穷循环,完全按照LZ的要求来的,有什么"令人发疯"的?
l999358 2008-10-30
  • 打赏
  • 举报
回复
已经解决了,不适你说的,是用的

struct timeval tv;
gettimeofday (&tv, 0);

呵呵,不过分给你算了.
Arthur_ 2008-10-30
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

clock_t s;

int main(int argc, char** argv)
{
again:
s = (unsigned long) times( NULL );
printf ("now is : %ld\n", s); //clock_t 是 long类型
sleep (1);
goto again;
return 0;
}

69,377

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧