| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:我编的一个管理系统不知道怎么改错误,请高手指教
只看楼主 加入收藏
biaoliangzdm
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-7-18
结帖率:100%
收藏
已结贴  问题点数:30 回复次数:6 
我编的一个管理系统不知道怎么改错误,请高手指教
#include"stdio.h"
#include"string.h"
#define EMPLOYEEMAX    100
struct employeeinfo
{
char name[20];
char sex[10];
}
FILE *infofile=NULL;
char filename='c:\\information'
void showmenu();
void inputinfo(struct employeeifo *);
void modinfo(strcu employeeinfo *);
void aboutinfo(struct employeeinfo *);
void allabout(struct employeeinfo *);
void delinfo(struct employeeinfo *);
int main(void)
{
struct employeeinfo employeemax[EMPLOYEEMAX];
struct employeeinfo *p_employee;
p_employee=employeemax;
int in;
do
 {
 clrscr();
 showmenu();
 switch(in)
  {
  scanf("%d",&in);
  case 1:inputinfo(p_employee);break;
  case 2:modinfo(p_employee);break;
  case 3:aboutinfo(p_employee);break;
  case 4:allabout(p_employee);break;
  case 5:delinfo(p_employee);break;
  case 6:break;
  default :printf("wrong choosing,please choose again");
  getch();
  clrscr();
  break;
  }
 }while(in!=6);
  getch();
  clrscr();
  return 0;
}

void showmenu(void)
{
printf("\n\n\n\n");
printf("\t\t  _____________________________________ \n");
printf("\t\t |     employee information manage     |\n");
printf("\t\t |_____________________________________|\n");
printf("\t\t |       1 : input  information        |\n");
printf("\t\t |       2 : modify information        |\n");
printf("\t\t |       3 : refer  information        |\n");
printf("\t\t |       4 : look-through information  |\n");
printf("\t\t |       5 : delete information        |\n");
printf("\t\t |         6 : get out sys               |\n");
printf("\t\t |_____________________________________|\n");
printf("\t\t\t please putin right choise");
}
void input(struct employeeinfo *p_employee);
{
int count=0;
char ch;
clrscr();
if((infofile=fopen(filename,"a+b"))==NULL)
 {
  printf("file wrong");
  getch();
  exit(1);
 }
rewind(infofile);
while(count<EMPLOYEEMAX)
 {
  printf("\nname");
  gets(p_employee[count].name);
  printf("\nsex");
  gets(p_employee[count].sex);
  fwrite(&p_employee[count++].name,sizeof(struct employeeinfo),1,infofile);
  printf("get in next?(y/n)");
  ch==getch();
  if(ch=='y'||ch=='Y')
  {
   clrscr();
   printf("please get in information");
   continue;
  }
  else
  {
   printf("get over ,back!");
   fclose(infofile);
   getch();
   clrscr();
   return ;
  }
 }
 return ;
}
void aboutinfo(struct employeeinfo *p_employee)
{
int i,count=0;
char ch;
char*temp=NULL;
clrscr();
if((infofile=fopen(filename,"rb"))==NULL)
 {
  printf("fail to open file,please cheack");
  getch();
  return ;
 }
rewind(infofile);
for(count=0;fread(&p_employee,sizeof(struct employeeinfo),1,infofile)==1,count++)
{continue;}
fclose(infofile);
if(count==0)
{
    printf("did not find information ,please cheack right");
    getch();
    clrscr();
    return ;
}
temp=(char *)malloc(20*sizeof(char));
printf("please input name you want to find\n");
while(gets(temp)!=NULL&&temp[0]!='\0')
{
    for(i=0;i<count;i++)
    {
        if(!strcmp(temp,p_employee[i].name))
        {
            clrscr();
            printf("the information is:");
            printf("\n name :p_employee[i].name");
            printf("\n sex :p_employee[i].sex");
            break;
        }
    }
    free(temp);
    printf("if you want to search next?(y/n)");
    ch=getch();
    if(ch=='y'||ch=='Y')
    {
        clrscr();
        temp=(char *)malloc(20*(char))
        printf("please inpur the name :\n");
        continue;
    }
    else
    {
        printf("search over get back by any key!");
        getch();
        clrscr();
        return ;
    }
}
    free(temp);
    printf("get back by any key");
    getch();
    clrscr;

}

void allabout(struct employeeinfo *p_employee)
{
    int i,count;
    clrscr();
    if((infofile=fopen(filename,"rb"))=NULL)
    {
        printff("fail to open file");
        getch();
        exit(1);
    }
    rewind(infofile);
    for(count=0;fread(&p_employeeinfo[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
    fclose(infofile);
    if(!count)
    {
        printf("can not get data");
        getch();
        clrscr();
        return ;
    }
    printf("the information is:\n");
    for(i=0;i<count;i++)
    {
        printf("name :%s",p_employeeinfo[i].name);
        printf("sex : %s",p_employeeinfo[i].sex);
        printf("please get any key to look next information");
        getch();
        clrscr();
    }
    getch();
    clrscr();
    return ;
}

void delinfo(struct p_employeeinfo *p_employee)
{
    int i,count;
    char ch;
    char *temp=NULL;
    clrscr();
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("fail to open file");
        getch();
        exit(1);
    }
    rewind(infofile);
    for(count=0;fread(&p_employeeinfo[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
    fclose(infofile);
    if(!count)
    {
        printf("can not get data");
        getch();
        return ;
    }
    temp=(char *)malloc(20*sizeof(char));
    printf("please getin the name :");
    while(gets(temp)!==NULL&&temp!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(!strcmp(temp,p_employeeinfo[i].name))
            {
                clrscr();
                printf("Do you want to delete this?(y/n)");
                if(ch=='n'||ch=='N')
                {
                    free(temp);
                    clrscr();
                    printf("get back by ane key ");
                    getch();
                    clrscr();
                    return ;
                }
                for(i=0;i<count;i++)p_employee[i]=p_employee[i+1];
                count--;
                if((infofile=fopen(filename,"w+b"))==NULL)
                {
                    printf("fail to open the file");
                    free(temp);
                    getch();
                    exit(1);
                }
                for(i=0;i<count;i++)if(fwrite(&p_employee[i],sizeof(struct employeeinfo),1,infofile)!=1)break;
                free(temp);
                clrscr();
                printf("do you want to delete next one?(y/n)");
                ch=getch();
                if(ch=='n'||ch=='N')
                {
                    fclose(infofile);
                    clrscr();
                    return ;
                }
                else
                {
                    clrscr();
                    temp=(char *)malloc(20*sizeof(char));
                    printf("input name:");
                    break;
                }
            }
        }
        printf("can not find %s ,do you want to input again?(y/n)",temp);
        getch();
        if(ch=='Y'||ch=='y')
        {
            free(temp);
            temp=(char *)malloc(20*sizeof(char));
            clrscr();
            printf("please get in the name :");
            continue ;
        }
        else
        {
            free(temp);
            clrscr();
            return ;
        }
    }
    free(temp);
    getch();
    clrscr();
}
void modinfo(strcu employeeinfo *p_employee)
{
  int count,i,n;
  char *temp;
  char *new;
  clrscr();
  if((infofile=fopen(filename,"rb"))==NULL)
  {
  printf("fail to open the file");
  getch();
  exit(1);
  }
  rewind(infofile)
  for(count=0;fread(&p_employee[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
  fclose(infofile);
  temp=(char *)malloc(20*sizeof(char));
  new=(char *)malloc(20*sizeof(char));
  printf("please input the name you want to change");
  gets(temp);
  for(i=0;i<count&&temp!=NULL&&temp!='\0';count++)
  {
  if(!strcmp(temp,p_employee[i].name))printf("1:%s 2:%s",p_employee[i].name,p_employee[i].sex);
  }
  printf("get out by "0"");
  printf("chose what you want to change:\n ");
  switch(n)
  {
  scanf("%d",&n);
  case 1:
    {
    printf("\nplease get in new information\n");
    gets(new);
    strcop(p_enployee[i].name,new);
    break;
    }
  case 2:
    {
    printf("please get in new information:\n")
    gets(new);
    strcop(p_emlopyee[i].sex,new);
    break;
    }
  case 0:break;
  default :printf("wrong choise")
  getch();
  clrscr();
  break;
  }
  free(temp);
  free(new);
  infofile=fopen(filename,"w+b");
  for(i=0;i<count;i++)
  {
  if(fwrite(&p_employee[i],sizeof(struct employeeinfo),1,infofile)==1)
  coutinue;
  else
  {
   fclose(infofile);
   printf("fail to change information");
   getch();
   clrscr();
   return ;
  }
  }
  fclose(infofile);
  return ;

}



搜索更多相关主题的帖子: 系统 指教 管理 
2010-07-21 21:22
biaoliangzdm
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-7-18
收藏
得分:0 
回复 楼主 biaoliangzdm
这个是我们的作业必须在TC上运行。请各位高手帮忙改下明天就要交了  谢谢啦!!
2010-07-21 21:24
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:20 
#include"stdio.h"
#include"string.h"
#define EMPLOYEEMAX    100
struct employeeinfo
{
char name[20];
char sex[10];
};

FILE *infofile=NULL;
char filename[]="c:\\information";
void showmenu();
void inputinfo(struct employeeifo *);
void modinfo(strcu employeeinfo *);
void aboutinfo(struct employeeinfo *);
void allabout(struct employeeinfo *);
void delinfo(struct employeeinfo *);
int main(void)
{
struct employeeinfo employeemax[EMPLOYEEMAX];
struct employeeinfo *p_employee;
p_employee=employeemax;
int in;
do
{
clrscr();
showmenu();
switch(in)
  {
  scanf("%d",&in);
  case 1:inputinfo(p_employee);break;
  case 2:modinfo(p_employee);break;
  case 3:aboutinfo(p_employee);break;
  case 4:allabout(p_employee);break;
  case 5:delinfo(p_employee);break;
  case 6:break;
  default :printf("wrong choosing,please choose again");
  getch();
  clrscr();
  break;
  }
}while(in!=6);
  getch();
  clrscr();
  return 0;
}

void showmenu(void)
{
printf("\n\n\n\n");
printf("\t\t  _____________________________________ \n");
printf("\t\t |     employee information manage     |\n");
printf("\t\t |_____________________________________|\n");
printf("\t\t |       1 : input  information        |\n");
printf("\t\t |       2 : modify information        |\n");
printf("\t\t |       3 : refer  information        |\n");
printf("\t\t |       4 : look-through information  |\n");
printf("\t\t |       5 : delete information        |\n");
printf("\t\t |         6 : get out sys               |\n");
printf("\t\t |_____________________________________|\n");
printf("\t\t\t please putin right choise");
}
void input(struct employeeinfo *p_employee);
{
int count=0;
char ch;
clrscr();
if((infofile=fopen(filename,"a+b"))==NULL)
{
  printf("file wrong");
  getch();
  exit(1);
}
rewind(infofile);
while(count<EMPLOYEEMAX)
{
  printf("\nname");
  gets(p_employee[count].name);
  printf("\nsex");
  gets(p_employee[count].sex);
  fwrite(&p_employee[count++].name,sizeof(struct employeeinfo),1,infofile);
  printf("get in next?(y/n)");
  ch==getch();
  if(ch=='y'||ch=='Y')
  {
   clrscr();
   printf("please get in information");
   continue;
  }
  else
  {
   printf("get over ,back!");
   fclose(infofile);
   getch();
   clrscr();
   return ;
  }
}
return ;
}
void aboutinfo(struct employeeinfo *p_employee)
{
int i,count=0;
char ch;
char*temp=NULL;
clrscr();
if((infofile=fopen(filename,"rb"))==NULL)
{
  printf("fail to open file,please cheack");
  getch();
  return ;
}
rewind(infofile);
for(count=0;fread(&p_employee,sizeof(struct employeeinfo),1,infofile)==1,count++)
{continue;}
fclose(infofile);
if(count==0)
{
    printf("did not find information ,please cheack right");
    getch();
    clrscr();
    return ;
}
temp=(char *)malloc(20*sizeof(char));
printf("please input name you want to find\n");
while(gets(temp)!=NULL&&temp[0]!='\0')
{
    for(i=0;i<count;i++)
    {
        if(!strcmp(temp,p_employee[i].name))
        {
            clrscr();
            printf("the information is:");
            printf("\n name :p_employee[i].name");
            printf("\n sex :p_employee[i].sex");
            break;
        }
    }
    free(temp);
    printf("if you want to search next?(y/n)");
    ch=getch();
    if(ch=='y'||ch=='Y')
    {
        clrscr();
        temp=(char *)malloc(20*(char))
        printf("please inpur the name :\n");
        continue;
    }
    else
    {
        printf("search over get back by any key!");
        getch();
        clrscr();
        return ;
    }
}
    free(temp);
    printf("get back by any key");
    getch();
    clrscr;

}

void allabout(struct employeeinfo *p_employee)
{
    int i,count;
    clrscr();
    if((infofile=fopen(filename,"rb"))=NULL)
    {
        printff("fail to open file");
        getch();
        exit(1);
    }
    rewind(infofile);
    for(count=0;fread(&p_employeeinfo[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
    fclose(infofile);
    if(!count)
    {
        printf("can not get data");
        getch();
        clrscr();
        return ;
    }
    printf("the information is:\n");
    for(i=0;i<count;i++)
    {
        printf("name :%s",p_employeeinfo[i].name);
        printf("sex : %s",p_employeeinfo[i].sex);
        printf("please get any key to look next information");
        getch();
        clrscr();
    }
    getch();
    clrscr();
    return ;
}

void delinfo(struct p_employeeinfo *p_employee)
{
    int i,count;
    char ch;
    char *temp=NULL;
    clrscr();
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("fail to open file");
        getch();
        exit(1);
    }
    rewind(infofile);
    for(count=0;fread(&p_employeeinfo[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
    fclose(infofile);
    if(!count)
    {
        printf("can not get data");
        getch();
        return ;
    }
    temp=(char *)malloc(20*sizeof(char));
    printf("please getin the name :");
    while(gets(temp)!==NULL&&temp!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(!strcmp(temp,p_employeeinfo[i].name))
            {
                clrscr();
                printf("Do you want to delete this?(y/n)");
                if(ch=='n'||ch=='N')
                {
                    free(temp);
                    clrscr();
                    printf("get back by ane key ");
                    getch();
                    clrscr();
                    return ;
                }
                for(i=0;i<count;i++)p_employee[i]=p_employee[i+1];
                count--;
                if((infofile=fopen(filename,"w+b"))==NULL)
                {
                    printf("fail to open the file");
                    free(temp);
                    getch();
                    exit(1);
                }
                for(i=0;i<count;i++)if(fwrite(&p_employee[i],sizeof(struct employeeinfo),1,infofile)!=1)break;
                free(temp);
                clrscr();
                printf("do you want to delete next one?(y/n)");
                ch=getch();
                if(ch=='n'||ch=='N')
                {
                    fclose(infofile);
                    clrscr();
                    return ;
                }
                else
                {
                    clrscr();
                    temp=(char *)malloc(20*sizeof(char));
                    printf("input name:");
                    break;
                }
            }
        }
        printf("can not find %s ,do you want to input again?(y/n)",temp);
        getch();
        if(ch=='Y'||ch=='y')
        {
            free(temp);
            temp=(char *)malloc(20*sizeof(char));
            clrscr();
            printf("please get in the name :");
            continue ;
        }
        else
        {
            free(temp);
            clrscr();
            return ;
        }
    }
    free(temp);
    getch();
    clrscr();
}
void modinfo(strcu employeeinfo *p_employee)
{
  int count,i,n;
  char *temp;
  char *new;
  clrscr();
  if((infofile=fopen(filename,"rb"))==NULL)
  {
  printf("fail to open the file");
  getch();
  exit(1);
  }
  rewind(infofile)
  for(count=0;fread(&p_employee[count],sizeof(struct employeeinfo),1,infofile)==1;count++)continue;
  fclose(infofile);
  temp=(char *)malloc(20*sizeof(char));
  new=(char *)malloc(20*sizeof(char));
  printf("please input the name you want to change");
  gets(temp);
  for(i=0;i<count&&temp!=NULL&&temp!='\0';count++)
  {
  if(!strcmp(temp,p_employee[i].name))printf("1:%s 2:%s",p_employee[i].name,p_employee[i].sex);
  }
  printf("get out by "0"");
  printf("chose what you want to change:\n ");
  switch(n)
  {
  scanf("%d",&n);
  case 1:
    {
    printf("\nplease get in new information\n");
    gets(new);
    strcop(p_enployee[i].name,new);
    break;
    }
  case 2:
    {
    printf("please get in new information:\n")
    gets(new);
    strcop(p_emlopyee[i].sex,new);
    break;
    }
  case 0:break;
  default :printf("wrong choise")
  getch();
  clrscr();
  break;
  }
  free(temp);
  free(new);
  infofile=fopen(filename,"w+b");
  for(i=0;i<count;i++)
  {
  if(fwrite(&p_employee[i],sizeof(struct employeeinfo),1,infofile)==1)
  coutinue;
  else
  {
   fclose(infofile);
   printf("fail to change information");
   getch();
   clrscr();
   return ;
  }
  }
  fclose(infofile);
  return ;

}
改好了,你看看
收到的鲜花

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-22 11:29
qingmeisu200
Rank: 4
等 级:业余侠客
帖 子:113
专家分:215
注 册:2010-3-16
收藏
得分:0 
这么长怎么有时间给你调啊 ,,你不会用vc调试吗

我能!
2010-07-22 11:45
biaoliangzdm
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-7-18
收藏
得分:0 
我用TC始终改不正确,没想到用vc,呵呵谢谢拉,还有点小错误但是能改了,主要老师用TC检查作业,我们也用TC编了没有办法
2010-07-22 12:22
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:10 
呵呵,希望你的作业能被老师表扬

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-22 19:06
biaoliangzdm
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-7-18
收藏
得分:0 
哈哈,谢拉,通过了
2010-07-24 14:44
快速回复:我编的一个管理系统不知道怎么改错误,请高手指教
数据加载中...
 
   



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

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