User Tools

Site Tools


c

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
c [2009/08/13 09:46] tkbletscc [2009/08/13 09:51] (current) tkbletsc
Line 1: Line 1:
-getopt +GO TO THE C [[c:index]].
-<code=c+
-#include <unistd.h> +
-#include <stdio.h> +
-#include <stdlib.h>+
  
-#define die(...) { fprintf(stderr, __VA_ARGS__); exit(1); } 
-#define pdie(s) { perror(s); exit(1); } 
- 
- 
-int main (int argc, char** argv) { 
- 
- int o; 
- int opt_a; 
- char* opt_c; 
- while ((o = getopt (argc, argv, "abc:")) != -1) { 
- switch (o) { 
- case 'a': 
- opt_a = 1; 
- printf("a=yes\n"); 
- break; 
- case 'c': 
- opt_c = optarg; 
- printf("c='%s'\n",opt_c); 
- 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(&now,&t); 
- 
- sprintf(buf,"%04d%02d%02d-%02d%02d%02d",t.tm_year+1900,t.tm_mon+1,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec); 
-  
- 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(&tstr, NULL) < 0) { 
- fprintf(stderr,"gettimeofday failed\n"); 
- exit(-1); 
- } 
- 
- t=((tstr.tv_sec + tstr.tv_usec/(double)1000000)); 
- 
- return t; 
-} 
- 
-long long get_usec() { 
- struct timeval tv; 
- gettimeofday(&tv,NULL); 
- return tv.tv_sec*1000000+tv.tv_usec; 
-} 
- 
-</code> 
c.txt · Last modified: 2009/08/13 09:51 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki