■掲示板に戻る■ 全部 1- 101- 最新50

Solaris vs Windows

144 :これで勝負だ2 :2001/08/19(日) 16:31
/* >>137-139 の出力フォーマットに合わせてみた */

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

#ifndef GT_MAX
#define GT_MAX 16
#endif

typedef struct {
 long rate;
 const char *name;
} ostype;

static ostype os[] = {{0, "FreeBSD"}, {0, "Linux"}, {0, "Solaris"}, {0, "Windows"}};

#define arraylen(a) (sizeof a/sizeof *a)

int
cmpfn(const void *s1, const void *s2) {
 return ((const ostype *)s1)->rate-((const ostype *)s2)->rate;
}

char *
repchr(int c, size_t len, char *buf, size_t buflen)
{
 if (len > buflen-1) len = buflen-1;
 memset(buf, c, len);
 buf[len] = 0;
 return buf;
}

int
main(int argc, char *const *argv)
{
 char buf[GT_MAX+3] = " ";
 int i;
 srand48((long)(time(NULL)^getpid()));
 for (i = 0; i < arraylen(os); i++) os[i].rate = lrand48();
 qsort(os, arraylen(os), sizeof *os, cmpfn);
 for (i = 0; i < arraylen(os); i++)
  printf("%s%s", os[i].name, i<arraylen(os)-1
    ?strcat(repchr('>', (os[i+1].rate-os[i].rate)/(LONG_MAX/GT_MAX+1)+1,
      buf+1, arraylen(buf)-2), " ")-1:"\n");
 return 0;
}


新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
名前: E-mail (省略可) :

read.cgi ver5.26+ (01/10/21-)