#include <stdio.h>
#include <string.h>
#include <time.h>
int main()
{
int i;
FILE *fp;
int n = 0;
int sum = 0;
fp = fopen("test.txt","r");
/*count real, user, and sys time */
clock_t start = clock();
while(!feof(fp))
{
fscanf(fp, "%d", &n);
sum += n;
}
if(sum > 100)
printf("Great.\n");
else
printf("...\n");
printf("Sum: %d", sum);
fclose(fp);
/*End...*/
clock_t end = clock();
float seconds = (float)(end - start) / CLOCKS_PER_SEC;
printf("\nTime: %lf\n", seconds);
return 0;
}
在test.txt中:
1 2 3 4 5
6 7 8 9 10
输出:
sh-4.3 $ main
...
总和:55
时间:0.000102
我的目标是计算实际,用户和系统输出的时间。
那么,这个时间被视为实时吗?
如果是,如何计算用户和系统时间?