分类: C/C++
2010-01-10 18:02:29
char *sstrcat(char *to, char *from)
{
sstrcpy(to + strlen(to), from);
return to;
}
(2)determine the size of a file.
long flength(char *fname)
{
FILE *fptr;
long length = 0L;
fptr = fopen(fname, "rb");
if(fptr != NULL)
{
fseek(fptr, 0L, SEEK_END);
length = ftell(fptr);
fclose(fptr);
}
return length;
}
(3)
/* round to integer */
#define iround(x) floor((x)+0.5)
/* round number n to d decimal points */
#define fround(n,d) (floor((n)/pow(.1,(d))+.5)*pow(.1,(d)))
(4)shell sort an array of strings
void strsort (char **array, size_t array_size)
{
size_t gap, i, j;
char **a, **b, *tmp;
for (gap = 0; ++gap < array_size; )
gap *= 2;
while (gap /= 2)
{
for (i = gap; i < array_size; i++)
{
for (j = i - gap; ;j -= gap)
{
a = array + j;
b = a + gap;
if (strcmp(*a, *b) <= 0)
break;
tmp = *a;
*a = *b;
*b = tmp;
if (j < gap)
break;
}
}
}
}