考虑以下代码:
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <signal.h>
const int NUM_SECONDS = 1;
int main()
{
int count = 1;
volatile sig_atomic_t flag = false;
double time_counter = 0;
clock_t this_time = clock();
clock_t last_time = this_time;
printf("Gran = %ld\n", NUM_SECONDS * CLOCKS_PER_SEC);
while(1)
{
this_time = clock();
time_counter += (double)(this_time - last_time);
last_time = this_time;
if(time_counter > (double)(NUM_SECONDS * CLOCKS_PER_SEC))
{
time_counter -= (double)(NUM_SECONDS * CLOCKS_PER_SEC);
flag = true;
count++;
}
if (flag == true)
{
flag = false;
printf ("%d", count);
}
}
return 0;
}
printf()
打印按预期计算IF&#39; \ n&#39;包含在格式说明符中。它不会使用上面的代码打印任何内容。请提出任何建议。