| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 586 人关注过本帖
标题:我的管理系统怎们创建不起文件呢? 高手帮忙看哈
只看楼主 加入收藏
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
结帖率:83.33%
收藏
已结贴  问题点数:20 回复次数:8 
我的管理系统怎们创建不起文件呢? 高手帮忙看哈
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>   
#define N 100

struct student
{   
    char num[5];
    char name[10];
    char sex[5];
    char age[5];
    char xueli[10];
    char gongzi[5];
    char address[10];
    char tel[11];
};


void myprint();
void mycreate();
void mydisplay();
void mysearch();

void sch_num(FILE *fp);
void sch_xueli(FILE *fp);
void myadd();
void mymodify();

void mydelete();  

void del_num(FILE *fp);
void del_xueli(FILE *fp);

void main()
{  
    char choose,yes_no;
   
    do
    {
        myprint();   
        printf("         ");
        choose=getch();
        switch(choose)
        {
            case '1':    mycreate();        break;        
            case '2':    mydisplay();    break;   
            case '3':    mysearch();        break;        
            case '4':    mymodify();        break;        
            case '5':   myadd();        break;
            case '6':    mydelete();          break;
            case '0':    break;
            default:printf("\n    %c error!\n",choose);
        }
        if(choose=='0')
            break;
        printf("\n        continue(Y/N)?\n");
        do
        {
            yes_no=getch();
        }while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');
    }while(yes_no!='Y'||yes_no!='y');
}

void myprint()
{
    printf("\n\n\n\n\n\n\n\n");
    printf("            |----------------------------|\n");
    printf("            |        shuru(0-5):  |\n");
    printf("            |----------------------------|\n");
    printf("            |    1--chuanjianxinxi    |\n");
    printf("            |    2--xianshixinxi         |\n");
    printf("            |    3--chaxuxinxi        |\n");
    printf("            |    4--xiugaixinxi         |\n");
    printf("            |    5--shanchuxinxi         |\n");
    printf("            |    0--tuichu            |\n");
    printf("            |----------------------------|\n");
}


void mycreate()
{
    int i=1;
    struct student temp;
    FILE *fp;
   
    fp=fopen("d:\\guanli.txt","w");
    if(fp==NULL)
    {
        printf("\n        da kai shi bai!\n");
        return;
    }      
   
    printf("\n        shu ru di 1 ge ji lu:\n");
    printf("        hao ma(yong #jie su shu ru ):");  
    do
    {
        gets(temp.num);
    }while(strcmp(temp.num,"")==0);
    printf("        xingming(yong # jie su shu ru):");
    gets(temp.name);
    printf("        xingbie(yong #jie su shu ru):");
    gets(temp.sex);   
    printf("        nian ling(yong # jie su shu ru):");
    gets(temp.age);
    printf("        xue li(yong # jie su shu ru):");
    gets(temp.xueli);
    printf("        gongzi(yong # jie su shu ru):");
    gets(temp.gongzi);
    printf("        zhu zi(yong # jie su shu ru):");
    gets(temp.address);
    printf("        dianhua(yong # jie su shu ru):");
    gets(temp.tel);
    while(temp.num[0]!='#'&&temp.name[0]!='#'&&temp.sex[0]!='#'&&temp.age[0]!='#'&&temp.xueli[0]!='#'&&temp.gongzi[0]!='#'&&temp.address[0]!='#'&&temp.tel[0]!='#')
    {
        fprintf(fp,"%5s%10%5s%5s%10s%5s%5s%11s\n",temp.num,temp.name,temp.sex,temp.age,temp.xueli,temp.address,temp.tel);
        i++;     
        printf("\n        shu ru di %d ge ji lu:\n",i);  
        printf("        hao ma(yong # jie su shu ru):");  
        do
        {
            gets(temp.num);
        }while(strcmp(temp.num,"")==0);
        printf("        xing ming(yong # jie su shu ru):");
        gets(temp.name);
        printf("        xing bie(yong # jie su shu ru):");
        gets(temp.sex);   
        printf("        nian ling(yong # jie su shu ru):");
        gets(temp.age);
        printf("        xue li(yong # jie su shu ru):");
        gets(temp.xueli);
        printf("        gongzi(yong # jie su shu ru):");
        gets(temp.gongzi);
        printf("        zhu zhi(yong # jie su shu ru):");
        gets(temp.address);
        printf("        dian hua(yong # jie su shu ru):");
        gets(temp.tel);
    }
   
    fclose(fp);
}


void mydisplay()
{
    int n=0;
    struct student temp;
    FILE *fp;  
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }   
   
    clrscr();
    printf("haoma    xingming    xingbie        nianling    xueli    gongzi    zhuzi    dianhua\n");
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",&temp.num,&temp.name,&temp.sex,&temp.age,&temp.xueli,&temp.gongzi,&temp.address,&temp.tel);
        printf("%5s%10s%5s%5s%10s%5s%10s%11s\n",temp.num,temp.name,temp.sex,temp.age,temp.xueli,temp.gongzi,temp.address,temp.tel);
        n++;
    }
    if(n==0)
        printf("\n        wen jian zhong wu ji lu!\n");
    else
        printf("\n        wen jian zhong gong %d ge ji lu \n",n);  
    fclose(fp);
}      
void mysearch()
{
    char c;
    FILE *fp;
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }            
   
    printf("\n        an xue li cha xu(h),an xing ming cha xu(m)?");
    c=getch();
    if(c=='h'||c=='H')
        sch_xueli(fp);        
    if(c=='m'||c=='M')
        sch_num(fp);        
    else
        printf("\n        fei fa zi fu!\n");     
    fclose(fp);
}
void sch_num(FILE *fp)
{
    int flag=0,n=0;
    char tempnum[10];
    struct student temp;
   
    printf("\n        shu ru cha xu xue hao:");
    gets(tempnum);  
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",&temp.num,&temp.name,&temp.sex,&temp.age,&temp.xueli,&temp.gongzi,&temp.address,&temp.tel);
        if(strcmp(tempnum,temp.num)==0)
        {
            if(flag==0)  
                printf("    haoma        xingming        xingbie            nianling        xueli        gongzi        zhuzi        dianhua\n");
            printf("%5s%10s%5s%5s%10s%5s%10s%11s\n",temp.num,temp.name,temp.sex,temp.age,temp.xueli,temp.gongzi,temp.address,temp.tel);
            flag=1;
        }
        n++;
    }
    if(n==0)
        printf("\n        wen jian wu ji lu!\n");
    else
        if(flag==0)
            printf("\n        wen jian zhong wu ci ren!\n");  
}      
void sch_xueli(FILE *fp)
{
    int flag=0,n=0;
    char tempxueli[10];
    struct student temp;
   
    printf("\n        shu ru cha xu xue li:");
    gets(tempxueli);  
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",&temp.num,&temp.name,&temp.sex,&temp.age,&temp.xueli,&temp.gongzi,&temp.address,&temp.tel);
        if(strcmp(tempxueli,temp.xueli)==0)
        {
            if(flag==0)  
                printf("haoma    xingming    xingbie    nianling    xueli    gongzi    zhuzi    dianhua\n");
            printf("%5s%10s%5s%5s%10s%5s%10s%11s\n",temp.num,temp.name,temp.sex,temp.age,temp.xueli,temp.gongzi,temp.address,temp.tel);
            flag=1;
        }
        n++;
    }
    if(n==  0)
        printf("\n    wen jian wu ji lu!\n");
    else
        if(flag==0)
            printf("\n        wen jian zhong wu ci ren!\n");  
}     
void mymodify()
{
    char c;
    int n=0;
    struct student *find,temp,record[100],*p;
    FILE *fp;
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }            
   
    p=record;
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
        p++;
        n++;
    }
    fclose(fp);
   
    if(n==0)
    {
        printf("\n    wen jian zhong wu ji lu!\n");   
        return;
    }
    printf("\n        shu ru xiu gai hao ma:");
    gets(temp.num);   
    for(p=record;p<record+n;p++)
        if(strcmp(temp.num,p->num)==0)
        {
            find=p;     
            break;
        }  
    if(p==record+n)
    {
        printf("\n        wu ci ren !\n");
        return;
    }
    do
    {
        printf("\n        shu ru zheng que de hao ma:");
        do
        {
            gets(temp.num);
        }while(strcmp(temp.num,"")==0);
        printf("        shu ru zheng que de xing ming:");
        gets(temp.name);   
        printf("        shu ru zheng que de xing bie:");
        gets(temp.sex);  
        printf("        shu ru zheng que de nian ling:");
        gets(temp.age);
        printf("        shu ru zheng que de xue li:");
        gets(temp.xueli);
        printf("        shu ru zheng que de gong zi:");
        gets(temp.gongzi);
        printf("        shu ru zheng que de zhu zi:");
        gets(temp.address);
        printf("        shu ru zheng que de dian hua:");
        gets(temp.tel);
        for(p=record;p<record+n;p++)
            if((strcmp(temp.num,p->num)==0)&&(p!=find))
            {
                printf("\n        hao ma chong fu chong xin shu ru(Y/N)?");
                do
                {
                    c=getch();
                }while(c!='Y'&&c!='y'&&c!='N'&&c!='n');
                putchar('\n');
                break;            
            }      
        if(p==record+n)
        {
            *find=temp;      
            break;
        }
    }while(c=='Y'||c=='y');
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian zhi bai!\n");
        return;
    }
    for(p=record;p<record+n;p++)
        fprintf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s%\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);   
    fclose(fp);        
}           


void myadd()
{
    char c;
    int n=0;
    struct student temp,record[N],*p;
    FILE *fp;
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }            
   
    p=record;
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
        p++;
        n++;
    }
    fclose(fp);
   
    do
    {
        printf("\n        shu ru xin ji lu hao ma:");
        do
        {
            gets(temp.num);
        }while(strcmp(temp.num,"")==0);
        printf("        shu ru xin ji lu xing ming:");
        gets(temp.name);   
        printf("        shu ru xin ji lu xing bie:");
        gets(temp.sex);
        printf("        shu ru xin ji lu nian ling:");
        gets(temp.age);
        printf("        shu ru xin ji lu xue li:");
        gets("temp.xueli");
        printf("        shu ru xin ji lu gong zi:");
        gets(temp.gongzi);
        printf("        shu ru xin ji lu zhu zi:");
        gets(temp.address);
        printf("        shu ru xin ji lu dian hua:");
        gets(temp.tel);
        for(p=record;p<record+n;p++)
            if(strcmp(temp.num,p->num)==0)
            {
                printf("\n    hao ma chong fu chong xin shu ru?(Y/N)?");
                do
                {
                    c=getch();
                }while(c!='Y'&&c!='y'&&c!='N'&&c!='n');
                putchar('\n');
                break;            
            }      
        if(p==record+n)
        {
            *p=temp;         
            break;
        }
    }while(c=='Y'||c=='y');
   
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }
    for(p=record;p<record+n+1;p++)
        fprintf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);   
    fclose(fp);        
}
void mydelete()
{
    char c;
    FILE *fp;
    fp=fopen("d:\\guanli.txt","r+");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }   
   
    printf("\n        an hao ma shan chu(h),an xu li shan chu(m)?");
    c=getch();
    if(c=='h'||c=='H')
        del_num(fp);   
    if(c=='m'||c=='M')
        del_xueli(fp);        
    else
        printf("\n        error!\n");     
    fclose(fp);
}   
void del_num(FILE *fp)
{
    int n=0;
    char tempnum[10];
    struct student record[N],*p,*k;
   
    p=record;
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
        p++;
        n++;
    }
    fclose(fp);  
   
    printf("\n        shu ru shan chu hao ma:");
    gets(tempnum);   
   
    for(k=record;k<record+n;k++)
        if(strcmp(tempnum,k->num)==0)
            break;            
    if(k<record+n)         
        for(p=k;p<k+n-1;p++)   
            *p=*(p+1);  
    else
        printf("\n        wu chi ren!\n");
   
    fp=fopen("d:\\guanli.txt","w");
    if(fp==NULL)
    {
        printf("\n        da kai wen jian shi bai!\n");
        return;
    }  
   
    for(p=record;p<record+n-1;p++)
        fprintf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
}   


void del_xueli(FILE *fp)
{
    int n=0;
    char tempxueli[10];
    struct student record[N],*p,*k;
     
   
    p=record;
    while(feof(fp)==0)
    {
        fscanf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
        p++;
        n++;
    }
    fclose(fp);  
   
    printf("\n        shu ru shan chu xue li:");
    gets(tempxueli);   
   
    for(k=record;k<record+n;k++)
        if(strcmp(tempxueli,k->xueli)==0)
            break;        
    if(k<record+n)         
        for(p=k;p<k+n-1;p++)  
            *p=*(p+1);  
    else
        printf("\n        wu ci ren!\n");
   
    fp=fopen("d:\\guanli.txt","w");
    if(fp==NULL)
    {
        printf("\n        da kain wen jian shi bai\n");
        return;
    }  
   
    for(p=record;p<record+n-1;p++)
        fprintf(fp,"%5s%10s%5s%5s%10s%5s%10s%11s\n",p->num,p->name,p->sex,p->age,p->xueli,p->gongzi,p->address,p->tel);
}   
搜索更多相关主题的帖子: 系统 文件 管理 
2010-05-25 17:03
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
主要就是那个creat()   函数   创建不起文件        假如我在TXT文本文档里写好像又可以调用了
不知为什么?
2010-05-25 17:07
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
creat()  创建文件    display()显示函数     mysearch()显示函数    myadd()  增加函数        mymodify()  修改函数    mydelete()  删除函数
2010-05-25 17:11
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
谢谢大家了    看看吧   我弄了一周了   哪晓得要不得
2010-05-25 17:33
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
谢谢了   大家来看哈嘛  拜托了
2010-05-25 19:48
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
怎么没人呢?
2010-05-26 16:59
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:20 
哎```LZ呀`谁来了一看你的代码都不想在继续看的``

C是很结构的``你应该很多地方都没问题`只是文件创建不了

那请你只把创建文件的相关代码列出``并标记你有疑问的地方``

这样别人才好帮你的``

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2010-05-26 18:29
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:0 
我刚才找了以下没找到creat()的定义

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2010-05-26 18:33
TERMINATORXQ
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2009-11-10
收藏
得分:0 
定义了的啊  mycreate
2010-05-26 21:55
快速回复:我的管理系统怎们创建不起文件呢? 高手帮忙看哈
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041077 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved