⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readingreminder.c

📁 BBS上淘来的一大堆C源代码
💻 C
字号:
//version 1.0.2
#include<stdio.h>
#include<conio.h>
#include<mem.h>
#include<dos.h>
#include<bios.h>
//----------------------------------------------------------------------------
//graphics functions
void SetGraphicsMode(int RegisterAX)
{    asm{    mov ax,RegisterAX
            int 0x10
    }
}
struct RGB
{   char R,G,B;
};
void SetPaletteRegister(int index,RGB *color)
{    outp(0x03C6,0xFF);
    outp(0x03C8,index);
    outp(0x03C9,color->R);
    outp(0x03C9,color->G);
    outp(0x03C9,color->B);
}
void ColorSet()
{    RGB Ctab[101];
    int i;
    for(i=1;i<=100;++i)
    {    Ctab[i].R=(63-63L*i/100)/2;
        Ctab[i].G=63L*i/100;
        Ctab[i].B=0;
    }
    for(i=155;i<=255;++i)
    {    SetPaletteRegister(i,Ctab+i-154);
    }
}
void CLS()
{   _fmemset((void far *)0xA0000000,0,320*200);
    gotoxy(1,5);
}
void ProcessBar(int yposition,double Percent)
{    int x,y;
    if(yposition<100 || yposition>180)return;
    for(x=10;x<310;++x)
    {   pokeb(0xA000,yposition*320+x,1);
        pokeb(0xA000,(yposition+5)*320+x,1);
    }
    for(y=yposition;y<=yposition+5;++y)
    {    pokeb(0xA000,y*320+9,1);
        pokeb(0xA000,y*320+310,1);
    }
    for(x=10;x<3*Percent+10;++x)
        for(y=yposition+1;y<yposition+5;++y)
        {   pokeb(0xA000,y*320+x,155+(x-10)/3);
        }
}
//----------------------------------------------------------------------------
//struct Date and functions
struct Date
{    int year,month,day;
    int hour,min,sec;
};
void GetDate(Date *pd)
{    date dump;
    time t;
    getdate(&dump);
    pd->year=dump.da_year;
    pd->month=dump.da_mon;
    pd->day=dump.da_day;
    gettime(&t);
    pd->hour=t.ti_hour;
    pd->min=t.ti_min;
    pd->sec=t.ti_sec;
}
void ReadDate(Date *pd,FILE *fin)
{    fscanf(fin,"%d%d%d",&(pd->year),&(pd->month),&(pd->day));
    pd->hour=pd->min=pd->sec=0;
}
void DispDate(Date *pd)
{    printf("%4d%4d%4d\n",pd->year,pd->month,pd->day);
}
int isR(int year)
{    if(year%400==0 || (year%4==0 && year%100!=0))return 1;
    else return 0;
}
double SecFrom2000Start(Date *pd)
{    double ret;
    int days;
    int temp;
    int R;
    static daytab[][12]=
        {{31,28,31,30,31,30,31,31,30,31,30,31},
        {31,29,31,30,31,30,31,31,30,31,30,31}};
    temp=pd->year - 2000;
    if(temp<0)return -1;
    days=temp*365 + temp/4 - (temp/100)*3/4;
    R=isR(pd->year);
    for(temp=0;temp<pd->month-1;++temp)
    {    days+=daytab[R][temp];
    }
    days+=pd->day;
    ret = days * 24.0*3600.0;
    ret += pd->hour*3600.0;
    ret += pd->min*60.0;
    ret += pd->sec;
    return ret;
}
double DateSub(Date *pd1,Date *pd2)
{   double f1,f2;
    f1=SecFrom2000Start(pd1);
    f2=SecFrom2000Start(pd2);
    return f1-f2;
}
//----------------------------------------------------------------------------
//struct BookNode and functions
#define NAMESIZE 50
struct BookNode
{   char BookName[NAMESIZE];
    int PageNow,PageTotal;
    Date DateStart,DateEnd;
};
void ReadBookNode(BookNode *node,FILE *fin)
{   while(fgetc(fin)!='<')
        ;
    fseek(fin,-1,SEEK_CUR);
    fgets(node->BookName,NAMESIZE,fin);
    fscanf(fin,"%d%d",&(node->PageNow),&(node->PageTotal));
    ReadDate(&(node->DateStart),fin);
    ReadDate(&(node->DateEnd),fin);
}
void DispBookNode(BookNode *node)
{   double percent,i,j;
    Date today;
    printf("BookName:%s\n",node->BookName);
    printf("PageNow/PageTotal:%6d/%6d\n\n",node->PageNow,node->PageTotal);
    printf("DateStart:\t");
    DispDate(&(node->DateStart));
    printf("DateEnd:\t");
    DispDate(&(node->DateEnd));

    percent=(node->PageNow)*100.0/(node->PageTotal);
    gotoxy(5,15);
    printf("percent complete:%8.4lf%%",percent);
    ProcessBar(120,percent);
    while(bioskey(1)==0)
    {    GetDate(&today);
        i=DateSub(&today,&(node->DateStart));
        j=DateSub(&(node->DateEnd),&(node->DateStart));
        percent=i*100.0/j;
        if(percent>100.0)
            percent=100;
        gotoxy(5,18);
        printf("time passed:%13.8lf%%",percent);
        ProcessBar(144,percent);
        gotoxy(5,21);
        printf("time left:%15.8lf%%",100.0-percent);
        ProcessBar(168,100.0-percent);
        putchar('\n');
    }
}
//----------------------------------------------------------------------------
//struct BookList and functions
typedef struct BookListNode
{    BookNode data;
    BookListNode *next;
} *BookList;
BookList glb_booklist = new BookListNode;
int ReadBookList(char *filename)
{   int Count,n;
    FILE *fin;
    BookListNode *p,*q;
    fin=fopen(filename,"r");
    if(!fin)return -1;
    fscanf(fin,"%d",&Count);
    n=Count;
    p=glb_booklist;
    while(n--)
    {   q=p;
        p=new BookListNode;
        ReadBookNode(&(p->data),fin);
        q->next=p;
    }
    p->next=NULL;
    fclose(fin);
    return Count;
}
void DispBookList()
{    BookListNode *p;
    p=glb_booklist->next;
    while(p)
    {    DispBookNode(&(p->data));
        p=p->next;
        getch();
        CLS();
    }
}
void DestroyBookList()
{    BookListNode *p,*q;
    p=glb_booklist;
    while(p)
    {   q=p;
        p=p->next;
        delete q;
    }
}
int main()
{   int result;
    result = ReadBookList("D:\\data.txt");    //要改变文件路径的话,改这里。
    if(result<0)
    {   printf("Reading File Failed.\n");
        printf("Press Any Key to Continue...");
        getch();
        return 1;
    }
    SetGraphicsMode(0x0013);
    ColorSet();
    CLS();
    DispBookList();
    DestroyBookList();
    SetGraphicsMode(0x0003);
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -