c
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
c [2009/08/07 11:46] – tkbletsc | c [2009/08/13 09:51] (current) – tkbletsc | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | getopt | + | GO TO THE C [[c:index]]. |
- | <code=c> | + | |
- | #include <unistd.h> | + | |
- | #include < | + | |
- | #include < | + | |
- | int main (int argc, char** argv) { | ||
- | |||
- | int o; | ||
- | int opt_a; | ||
- | char* opt_c; | ||
- | while ((o = getopt (argc, argv, " | ||
- | switch (o) { | ||
- | case ' | ||
- | opt_a = 1; | ||
- | printf(" | ||
- | break; | ||
- | case ' | ||
- | opt_c = optarg; | ||
- | printf(" | ||
- | break; | ||
- | case '?': | ||
- | exit(1); | ||
- | } | ||
- | } | ||
- | argc -= optind; argv += optind; // throw away option arguments | ||
- | |||
- | } | ||
- | |||
- | char* timestamp() { | ||
- | static char buf[64]; | ||
- | struct tm t; | ||
- | |||
- | time_t now = time(NULL); | ||
- | localtime_r(& | ||
- | |||
- | sprintf(buf," | ||
- | |||
- | return buf; | ||
- | } | ||
- | |||
- | |||
- | /** | ||
- | * Returns the number of seconds since the epoch as a double-precision | ||
- | * float with microsecond resolution. | ||
- | * | ||
- | * @return Time since first call to this function | ||
- | */ | ||
- | double getCurrentTime() { | ||
- | double t; | ||
- | struct timeval tstr; | ||
- | |||
- | if (gettimeofday(& | ||
- | fprintf(stderr," | ||
- | exit(-1); | ||
- | } | ||
- | |||
- | t=((tstr.tv_sec + tstr.tv_usec/ | ||
- | |||
- | return t; | ||
- | } | ||
- | |||
- | long long get_usec() { | ||
- | struct timeval tv; | ||
- | gettimeofday(& | ||
- | return tv.tv_sec*1000000+tv.tv_usec; | ||
- | } | ||
- | |||
- | </ |
c.1249670796.txt.gz · Last modified: 2009/08/07 11:46 by tkbletsc