我正在尝试连续轮询时钟周期数并仅在周期计数为 100 + 开始时间时才打印我的语句。这样如果我的 start = 1000000,打印语句应该只在 end = 1000100 时执行 它应该显示例如假设在开始时,时间 = 1000000 您好,开始值:1000000 结束值: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);
}
最佳答案
我很确定这一行:
while(end=clock()< start + 100)
需要是这样的:
while( (end=clock()) < (start + 100) )
写得更好:
void main()
{
clock_t start = clock();
clock_t end = start;
while(end < (start + 100))
{
end = clock();
};
printf("Hello, value of start:%d and value of end:%d", (int)start, (int)end);
}
关于c - 轮询 C 中的时钟周期数 sw,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39823284/