回 帖 发 新 帖 刷新版面

主题:[原创]学生信息管理(c)---绝对原创(2)

void insert(void)
{
    char ch[20];
    nTemp=(struct student*)malloc(sizeof(struct student));
    show(3);
    cprintf("No:");
    gets(ch);
    nTemp->stuNo=rand()%100;/* nTemp->stuNo=atoi(ch); Use Rand() For Test. */
    gotoxy(2,2);
    clreol();
    gotoxy(31,2);
    putch(0xb3);
    gotoxy(2,2);
    cprintf("Name:");
    gets(nTemp->stuName);
    gotoxy(2,2);
    clreol();
    gotoxy(31,2);
    putch(0xb3);
    gotoxy(2,2);
    cprintf("Sex(m\\w):");
    nTemp->stuSex=getchar();getchar();
    if(nTemp->stuSex!='m'&&nTemp->stuSex!='w')
    {
        textbackground(3);
        window(20,10,50,13);
        clrscr();
        puttext(1,3,80,21,buf3);
        window(1,23,80,25);
        gotoxy(1,1);
        clreol();
        textcolor(15);
        cprintf(" Input Student Sex Error!");
        return;
    }
    gotoxy(2,2);
    clreol();
    gotoxy(31,2);
    putch(0xb3);
    gotoxy(2,2);
    cprintf("Maths:");gets(ch);
    nTemp->stuMaths=rand()%100;/*nTemp->stuMaths=atof(ch); Use Rand() For Test. */
    gotoxy(2,2);
    clreol();
    gotoxy(31,2);
    putch(0xb3);
    gotoxy(2,2);
    cprintf("Chinese:");gets(ch);
    nTemp->stuChinese=rand()%100;/*nTemp->stuChinese=atof(ch); Use Rand() For Test. */
    gotoxy(2,2);
    clreol();
    gotoxy(31,2);
    putch(0xb3);
    gotoxy(2,2);
    cprintf("English:");gets(ch);
    nTemp->stuEnglish=rand()%100;/*nTemp->stuEnglish=atof(ch); Use Rand() For Test. */
    nTemp->prev=NULL;
    nTemp->next=NULL;
    textbackground(3);
    window(20,10,50,13);
    clrscr();
    if(nHead==NULL)
    {
        nHead=nTail=nTemp;
    }
    else
    {
        nTail->next=nTemp;
        nTemp->prev=nTail;
        nTail=nTemp;
    }
    window(1,3,80,25);
    gotoxy(1,21);
    textcolor(15);
    clreol();
    cprintf(" Insert Data Complete.");
    pageCount=1;
    showPageCount();
    showPageData(pageCount);
}

void openFile(void)
{
    int key;
    char openfile[30];
    show(1);
    while((key=bioskey(0))==KEY_ESC)
    {
        return;
    }
    gets(openfile);
    if((fp=fopen(openfile,"r"))==NULL)
    {
        textbackground(3);
        window(1,3,80,14);
        clrscr();
        window(1,3,80,25);
        textcolor(15);
        gotoxy(1,21);
        cprintf("Cannot Open File.");
        return;
    }
    strcpy(fileName,openfile);
    nHead=nTail=NULL;
    textbackground(3);
    window(1,3,80,21);
    clrscr();
    textcolor(15);
    nTemp=(struct student*)malloc(sizeof(struct student));
    while(fread(nTemp,sizeof(struct student),1,fp)==1)
    {
        if(nTemp==NULL)
        {
            window(1,3,80,25);
            gotoxy(1,21);
            clreol();
            cprintf("File Is Empty.");
            return;
        }
        else
        {
            gotoxy(1,1);
            cprintf("No        Name           Sex        Maths        Chinese        English\n");
            if(nHead==NULL)
            {
                nHead=nTail=nTemp;
            }
            else
            {
                nTail->next=nTemp;
                nTemp->prev=nTail;
                nTail=nTemp;
                nTail->next=NULL;
            }
        }
        nTemp=(struct student*)malloc(sizeof(struct student));
    }
    pageCount=1;
    showPageCount();
    recordList();
    window(1,3,80,25);
    gotoxy(1,21);
    clreol();
    cprintf(" Open file %s complete.",openfile);
    gotoxy(1,22);
    cprintf(" File Name: %s",openfile);
}

void new(void)
{
    strcpy(fileName,"noname.txt");
    nHead=nTail=NULL;
    pageCount=1;
    textbackground(3);
    window(1,3,80,21);
    clrscr();
    window(1,3,80,25);
    gotoxy(1,21);
    clreol();
    textcolor(15);
    cprintf(" The file doesnot include data.Insert data first.Please!");
    gotoxy(1,22);
    clreol();
    cprintf(" File Name: noname.txt");    
    gotoxy(1,23);
    cprintf(" Page Number: %d",pageCount);
}

回复列表 (共3个回复)

沙发

学习了

板凳

顶一个,楼主辛苦了。

3 楼

为什么 写了这么多的 代码 竟然没有一行注释?

我来回复

您尚未登录,请登录后再回复。点此登录或注册