回文章列表
作者hpo14.bbs@ntust.org (陌生) 看板: itoc
標題[請問] 熱門看板的檔案
時間資工清流站 (2007/04/21 Sat 15:14:52)
精華區裡面有兩篇 qazq 大所作的熱門看板功能

但是第一篇裡面寫到「利用既有的usies-sort.c……」

新版的程式裡面並沒有這隻檔案。

小弟就從我舊站的 src/util 下把這隻程式co出來用。

然後照文章修改之後,順便把舊站的階級統計也修改上去。(改在 topusr.c)

然後重新 make 過後,精華中的利用 topusr.c 這隻程式產生的統計資料

就全部停住,不會更新了,就算我重開機跑個兩天也是一樣。

這是 account 被我改爛掉嗎?

我 topusr.c 改的只有如下

  #define OUTFILE_TOPGOLD   BBSHOME"/gem/@/@-topgold"
+ #define OUTFILE_LEVEL     BBSHOME"/gem/@/@-level"


  /* 我看一遍這兩行還是不懂這邊的%%%d%%s%%%ds是怎麼跑*/
- i = 12 - (strlen(title) >> 1);
- sprintf(buf, " \033[1;33m○ ──────────→ \033[41m%%%ds%%s%%%ds\033[40m ←────────── ○\033[m\n\n", i, i);
+ sprintf(buf, " \033[1;33m○ ──────────→ \033[41m%s [%2d月%2d日] \033[40m ←────────── ○\033[m\n\n",
               ptime->tm_mon + 1, ptime->tm_mday);
- fprintf(fp, buf, "", title, "");
+ fprintf(fp, buf, title);


以下程式新增在

/*-------------------------------------------------------*/
/* author : wsyfish.bbs@fpg.m4.ntu.edu.tw        */
/* target : 站上星座統計                 */
/*-------------------------------------------------------*/

前面

/*-------------------------------------------------------*/
/* target : 站上金幣階級統計                        */
/*-------------------------------------------------------*/
#define num_level 11
static int act_level[num_level];

static inline void
count_level(cuser)
  ACCT *cuser;
{
  int userno;
  int money1 = cuser->money;
  int money2 = cuser->gold * 200000;
  double allmoney = money1 + money2;

   if(allmoney > 0 && allmoney < 100)
    userno = 0;
   else if(allmoney < 1000)
    userno = 1;
   else if(allmoney < 5000)
    userno = 2;
   else if(allmoney < 10000)
    userno = 3;
   else if(allmoney < 500000)
    userno = 4;
   else if(allmoney < 1000000)
    userno = 5;
   else if(allmoney < 10000000)
    userno = 6;
   else if(allmoney < 100000000)
    userno = 7;
   else if(allmoney < 1000000000)
    userno = 8;
   else if(allmoney >= 1000000000)
    userno = 9;
   else
    userno = 10;

   ++act_level[userno];
}

static inline void
write_level(fpath, year, month, day)
  char *fpath;
  int year, month, day;
{
  FILE *fp;
  int i, j;
  int max, item, maxhoroscope;

  char *fortune[num_level] = {"三級貧民", "二級貧民", "一級貧民", "低收入戶", "
死老百姓", "小康之家", "百萬富翁", "千萬富翁", "億萬富翁", "    財閥", "破表!!
"};

  char *blk[10] =
  {
    "  ", "▏", "▎", "▍", "▌",
    "▋", "▊", "▉", "█", "█",
  };


  if ((fp = fopen(fpath, "w")) == NULL)
  {
    printf("cann't open %s\n", fpath);
    return;
  }

  max = maxhoroscope = 0;

  for (i = 0; i < num_level; i++)
  {
    if (act_level[i] > max)
    {
      max = act_level[i];
      maxhoroscope = i;
    }
  }

  item = max / 30 + 1;

  fprintf(fp, "\t\t\t \033[1;33;45m " BBSNAME " 階級統計 [%02d/%02d/%02d] \033[m\n\n", year % 100, month, day);

  for (i = 0; i < num_level; i++)
  {
    fprintf(fp, " \033[1;37m%15s \033[0;36m", fortune[i]);
    for (j = 0; j < act_level[i] / item; j++)
    {
      fprintf(fp, "%2s", blk[9]);
    }
    fprintf(fp, "%2s \033[1;37m%d\033[m\n\n",
                blk[(act_level[i] % item) * 10 / item], act_level[i]);
  }

  fclose(fp);
}



int
main()
{
    ……
  memset(&topgold, 0, sizeof(topgold));
+ memset(act_level, 0, sizeof(act_level));
  memset(act_age, 0, sizeof(act_age));
    ……

  qsort(topgold, TOPNUM, sizeof(DATA), sort_compare);
  write_data(OUTFILE_TOPGOLD, "金幣富豪抓狂榜", &topgold);

+  /* 階級統計 */
+  write_level(OUTFILE_LEVEL, year, month, day);

  write_age(OUTFILE_AGE, year, month, day);

}

--
>> 台灣科技大學 資工清流站 # ntust.org #
>> Author: 61.59.78.243
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻