This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* (char)i ? printf("l\n") : printf("b\n"); */ | |
#include <stdio.h> | |
int byteorder(void) | |
{ | |
int i = 0x0001; | |
(char)i ? printf("l\n") : printf("b\n"); | |
return i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use ftime() to calculate the execution time of millisecond */ | |
#include <sys/timeb.h> | |
long timecost(void (*dosomething)()) | |
{ | |
struct timeb begin, end; | |
long cost; | |
ftime(&begin); | |
dosomething(); | |
ftime(&end); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use gettimeofday() to calculate the execution time in microseconds */ | |
#include <sys/time.h> | |
long timecost(void (*dosomething)()) | |
{ | |
struct timeval start, end; | |
long cost; | |
gettimeofday(&start, NULL); | |
dosomething(); | |
gettimeofday(&end, NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use time() to calculate the execution time in second */ | |
#include <time.h> | |
long timecost(void (*dosomething)()) | |
{ | |
time_t start, end; | |
long cost; | |
start = time(NULL); | |
dosomething(); | |
end = time(NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use tolower() to convert string */ | |
#include <ctype.h> | |
char* strlwr(char *s) | |
{ | |
char *d = s; | |
while(*d) | |
*d++ = tolower(*d); | |
return s; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use toupper() to convert string */ | |
#include <ctype.h> | |
char* strupr(char *s) | |
{ | |
char *d = s; | |
while(*d) | |
*d++ = toupper(*d); | |
return s; | |
} |