Category : Files from Magazines
Archive   : MAR91.ZIP
Filename : 2N03026A

 
Output of file : 2N03026A contained in archive : MAR91.ZIP
#include
#include

/*
* arraycmp - a general-purpose array comparer in C
*/
typedef int (*cf_t)(const void *p, const void *q);

int arraycmp
(
const void *s1, const void *s2, size_t n, size_t size,
cf_t cf
)
{
const char *t1 = s1;
const char *t2 = s2;
size_t i;
int cmp;

for (i = 0; i < n * size; i += size)
if ((cmp = cf(t1 + i, t2 + i)) != 0)
return cmp;
return 0;
}

/*
* Some element comparison functions
*/
int intcf(const void *p, const void *q)
{
return *(int *)p - *(int *)q;
}

int doublecf(const void *p, const void *q)
{
if (*(double *)p < *(double *)q)
return -1;
else if (*(double *)p == *(double *)q)
return 0;
else
return 1;
}

int strcf(const void *p, const void *q)
{
return strcmp(p, q);
}

/*
* Sample calls to arraycmp...
*/
int a[] = {1, 2, 3, 4, -5};
int b[] = {1, 2, 3, 4, 4};

double f[] = {1, 2, 3, 4, 5};
double g[] = {1, 2, 3, 3, 4};

char *s[] = {"123", "456", "789"};
char *t[] = {"123", "789", "456"};

int main(void)
{
printf("a vs. b = %d\n",
arraycmp(a, b, 4, sizeof(int), intcf));
printf("a vs. b = %d\n",
arraycmp(a, b, 5, sizeof(int), intcf));
printf("f vs. g = %d\n",
arraycmp(f, g, 5, sizeof(double), doublecf));
printf("s vs. t = %d\n",
arraycmp(s, t, 3, sizeof(char *), strcf));
printf("s vs. t = %d\n",
arraycmp(s, t, 3, sizeof(char *), (cf_t)strcmp));
return 0;
}



  3 Responses to “Category : Files from Magazines
Archive   : MAR91.ZIP
Filename : 2N03026A

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/