Flash初哥

February 1, 2010

[C/C++]use gettimeofday to get time different

Filed under: C/C++ — Tags: — KAV @ 8:36 am
#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 );
}

error: ctime: No such file or directory

Filed under: C/C++ — Tags: , — KAV @ 8:16 am

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

Filed under: C/C++ — Tags: , — KAV @ 7:55 am

You can create a char array as follow:
char myStr[] = “text”;
char* myStr = “text”;

Powered by WordPress