summaryrefslogtreecommitdiffstats
path: root/util/openvice.c
blob: 9b5e438f9630af271e62de9647eba3fbed4fe78f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* $Id: openvice.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
/* 發票開獎小程式 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "config.h"
#include "pttstruct.h"
#include "util.h"

#define VICE_SHOW  BBSHOME "/etc/vice.show1"
#define VICE_BINGO BBSHOME "/etc/vice.bingo"
#define VICE_NEW   "vice.new"
#define VICE_DATA  "vice.data"
#define MAX_BINGO  99999999

int main()
{
    char TABLE[5][3] =
    {"一", "二", "三", "四", "五"};

    int i = 0, bingo, base = 0;


    FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w");

    extern struct utmpfile_t *utmpshm;
    resolve_utmp();

    srand(utmpshm->number);

    if (!fp || !fb )
    perror("error open file");


    bingo = rand() % MAX_BINGO;
    fprintf(fp, "%1c統一發票中獎號碼\n", ' ');
    fprintf(fp, "%1c================\n", ' ');
    fprintf(fp, "%1c特別獎: %08d\n\n", ' ', bingo);
    fprintf(fb, "%d\n", bingo);

    while (i < 5)
    {
    bingo = (base + rand()) % MAX_BINGO;
    fprintf(fp, "%1c第%s獎: %08d\n", ' ', TABLE[i], bingo);
    fprintf(fb, "%08d\n", bingo);
    i++;
    }
    fclose(fp);
    fclose(fb);
    return 0;
}