【发布时间】:2016-10-03 01:03:46
【问题描述】:
我正在尝试不断轮询时钟周期的数量并仅在周期计数为 100 + 开始时间时打印我的语句。这样,如果我的 start = 1000000,则仅当 end = 1000100 时才应执行打印语句 它应该显示例如假设在开始时,时间 = 1000000 你好,start 的值:1000000 和 end 的值:1000101
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
clock_t start,end;
start = clock();
while(end=clock() < (start + 100))
{};
printf("Hello, value of start:%d and value of end:%d", start, end);
}
但是我得到了 你好,start的值:0和end的值:0
我已经编辑了我的代码并获得了 end=0.0000 的值。这是我在下面编辑的代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
clock_t start;
start = clock();
clock_t end = start;
printf("Hello");
while(end < (start + 100))
{
end = clock();
};
printf("value of end is %f \n", end);
}
【问题讨论】: