#include <sys/time.h> #include <stdio.h> int main(){ struct timeval tv, tv2; unsigned long long start_utime, end_utime; gettimeofday(&tv,NULL); start_utime = tv.tv_sec * 1000000 + tv.tv_usec; usleep(1000); gettimeofday(&tv2,NULL); end_utime = tv2.tv_sec * 1000000 + tv2.tv_usec; printf(" runtime = %llu\n", end_utime - start_utime ); } |
February 1, 2010
[C/C++]use gettimeofday to get time different
error: ctime: No such file or directory
Today I do my csis0234 homework and find the following error:
error: ctime: No such file or directory
error: cstdlib: No such file or directory
…
anything wrong?
Answer:
Those are the C++ versions. Don’t use those in a C program. The C versions are
Code:
#include
#include
[C/C++] char array
You can create a char array as follow:
char myStr[] = “text”;
char* myStr = “text”;