#include <stdio.h>

enum { LINELEN = 256, NACCOUNT = 400 };

typedef struct {
    int year, month, day;  /* 年月日 */
    char outline[LINELEN]; /* 项目简记 */
    double amount;          /* 金额 */
} ACCITEM;

ACCITEM accbook[NACCOUNT];

int readitem(FILE *fp, ACCITEM *ip) {
    int n = fscanf(fp, "%d%d%d %s %lf", &ip->year, &ip->month, &ip->day,
                   ip->outline, &ip->amount); 
    return n == 5 ? 1 : n == EOF ? -1 : 0;
}

int readall(FILE *fp, int limit, ACCITEM accbook[]) {
    int i;
    while (i < limit) {
        switch(readitem(fp, &accbook[i])) {
            case 1:
                ++i;
                continue;
            case 0:
                /* ... 处理输入出错 */
                continue;
            case -1:
                ;      
        }
        break;
    }
}

int main() {
    int n, inum = 0;
    ACCITEM accbook[NACCOUNT];

    initialization();
    while ((n = getcommand()) >= 0) {
        switch (n) {
        case 0: /* 由用户得到账目文件名并读入 */
            inum = readfile(NACCOUNT, accbook); 
            break;
        case 1: /* 计算最终余额 */
            balance(inum, accbook);
            break;
        case 2: /* 统计所有收入 */
            receipts(inum, accbook);
            break;
        case 3: /* 统计所有支出 */
            expenditures(inum, accbook);
            break;
        case 4: /* 打印大额支出，向用户要求额度限制 */
            printsome(inum, accbook);
            break;
        default: /* 错误命令。输出错误信息 */
            errmessage();
            break;
        }
    }

    finalization();
    return 0;
}

