论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

一个产品治理系统

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:42:47

#include  <stdio.h>
#include  <string.h>
#include  <conio.h>
#define  SIZE 300
struct  product
{char id[3];
  char name[10];
  char gysh[10];
  char lb[11];
  char dwsl[11];
  char dj[10];
  char kcp[5];
  char dgl[6];
  char zdgl[6];
  char zz[5];}
   pro[SIZE];
void  myprint();
void  product();
void  myprint1();
void  mycreate();
void  mydisplay();
void  mysearch();
void  sch_num (FILE  *fp);
void  mymodify();
void  myadd();
void  mysave();
void  mydelete();
void  del_num(FILE  *fp);
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>

#include<stdio.h>
#include<stdlib.h>
#include <conio.h>
#include <malloc.h>
#define NULL 0    
void cliread();
void clichoose();
void cliprintmenu();
void clidisplay();
void cliadd();
void clisearch();
void climodify();
void clireturn();
void clidel();


typedef struct client
{
 char id[8];                      /*客户编号*/
 char name[25];                /*客户名称*/
 struct client *next;      
}CLI;
FILE *fpc;
CLI *Chead;


int transfer1(char *p,int n)
{int i,j;
 long sum=0,qu;
 for(i=0;i<n;i++)
  {for(j=n-1-i,qu=1;j>0;j--)
    qu=10*qu;
   sum=sum+(*(p+i)-'0')*qu;}
 return(sum+1);}

/*float transfer2(char *ca)
{float val,power,sum; int i=0,j;char s[20];
 printf("%s\n",*ca);
 for(i=0,j=0;i<13;i++)
  if(*(ca+i)='.'||(*(ca+i)>='0'&&*(ca+i)<='9')) s[j++]=*(ca+i);
 s[j]='\0';j=0;
 for(val=0;s[j]>='0'&&s[j]<='9';j++)
 val=10*val+s[j]-'0';
 if(s[j]=='.') j++;
 for(power=1;s[j]>='0'&&s[j]<='9';i++)
  {val=10*val+s[j]-'0'; power*=10;}

 sum=val/power;
 printf("%f\n",sum);
}*/
 
void print()
{FILE *pf;
 int n,i,j,l,cout=0;
 long k;
 char *ps;
 struct order *p;
 pf=fopen("d:\\dzs\\order3.txt","rb");
 fseek(pf,0l,2);
 k=ftell(pf); l=28; printf("k1=%ld\n",k);ps=(char *)malloc(k);
 fseek(pf,0l,0); fread(ps,1,k,pf);
 printf("                  order\n");
 for(i=0;i<k;i=i+28)
  {for(j=i;j<26+i;j++)
    putchar(*(ps+j));
   printf("\n");}
 printf("\n");
 printf("            ****请按回车****\n");
 getchar();
 fclose(pf);
 pf=fopen("d:\\dzs\\ordet.txt","rb");
 fseek(pf,0l,2);
 k=ftell(pf);printf("k2=%ld\n",k); l=44; ps=(char*)malloc(k);
 fseek(pf,0l,0); fread(ps,1,k,pf);
 printf("                   order detail\n");
 for(i=0;i<k;i=i+44)
  {for(j=i;j<42+i;j++)
    putchar(*(ps+j));
   printf("\n");}
 printf("\n");
 printf("            ****请按回车****\n");
 
}

void add()
{struct order{a[28];};
 struct ordet{a[44];};
 struct order *or;
 struct ordet *ot;
 char *temp,*or1,*or2;
 int i;
 long number;
 FILE *fp1,*fp2;
 if((fp1=fopen("d:\\dzs\\order3.txt","rb+"))==NULL)
  printf("error\n");
 fseek(fp1,-28l,2);
 temp=(char *)malloc(6);
 for(i=0;i<5;i++)
  *(temp+i)=fgetc(fp1);
 *(temp+i)='\0';
 number=transfer1(temp,5);
 printf("请输入订单信息:\n");
 printf("您将使用以下客户ID(请按以下方式输入:五个字符、三个空格):%ld\n",number);

 gets(or1);
 for(i=26;i<28;i++) *(or1+i)='\0';
 fclose(fp1);
 if((fp1=fopen("d:\\dzs\\order3.txt","ab+"))==NULL)
  printf("error\n");
 fwrite(or1,1,28,fp1);
 fclose(fp1);
 printf("please input order detail data:\n");
 printf("please write down your orderID:%d\n",number);
 printf("input orderID(5 bits and 7 space)\n");
 printf("input pro_name(13 bits)\n");
 printf("input price(13bits)\n");
 printf("input amount(4bits):\n");
 or2=(char *)malloc(44);
 gets(or2);
 for(i=42;i<44;i++) *(or2+i)='\0';
 if((fp2=fopen("d:\\dzs\\ordet.txt","ab+"))==NULL)
  printf("error\n");
 fwrite(or2,1,44,fp2);
 fclose(fp2);printf("                                 Sucess!\n");
 print();
 getchar();
 clrscr();


}


void search()
{FILE *p1,*p2;
 int i,j,tag1=0,tag2=0,l1,l2;
 long k1,k2;
 int num[20];
 char *ex,*ps1,*ps2;
 struct order {char ord[5];
        char spa1[3];
        char cus[5];
        char spa2[3];
        char dat[12];};
 struct ordet {char ord[5];
        char spa[7];
        char pro[13];
        char pri[13];
        char amo[6];};
 struct order *or;
 struct ordet *ot;
 if((p1=fopen("d:\\dzs\\order3.txt","rb"))==NULL)
  printf("error\n");
 printf("请输入客户ID:\n");
 ex=(char *)malloc(6);gets(ex);clrscr();
 fseek(p1,0l,2);k1=ftell(p1);ps1=(char *)malloc(k1);
 fseek(p1,0l,0);fread(ps1,1,k1,p1);l1=k1/28;
 for(i=0;i<l1;i++)
 {*(ps1+26+i*28)='\0';*(ps1+27+i*28)='\0';*(ps1+5+i*28)='\0';
  *(ps1+7+i*28)='\0';*(ps1+13+i*28)='\0';*(ps1+15+i*28)='\0';}
 or=(struct order *)ps1;
 for(i=0,j=0;i<l1;i++)
  if(strcmp(ex,(or+i)->cus)==0) {tag1=tag1+1;num[j++]=i;} fclose(p1);
 if(tag1!=0)
 {if((p2=fopen("d:\\dzs\\ordet.txt","rb"))==NULL)
   printf("error\n");
  fseek(p2,0l,2);k2=ftell(p2);ps2=(char *)malloc(k2);
  fseek(p2,0l,0);fread(ps2,1,k2,p2);l2=k2/44;
  for(i=0;i<l2;i++)
  {*(ps2+42+i*44)='\0';*(ps2+43+i*44)='\0';*(ps2+5+i*44)='\0';
   *(ps2+11+i*44)='\0';*(ps2+24+i*44)='\0';*(ps2+32+i*44)='\0';*(ps2+37+i*44)='\0';}
  ot=(struct ordet *)ps2;
  printf("********************************************************************************\n");
  printf("                         您的订单和订单明细如下\n");
  printf("\n");
  printf("********************************************************************************\n");
  for(j=0;j<tag1;j++)
   for(i=0;i<l2;i++)
    if(strcmp((ot+i)->ord,(or+num[j])->ord)==0)
     {printf("%s      %s      %s      %s     %s    %s     %s\n",(or+num[j])->ord,(or+num[j])->cus,(or+num[j])->dat,(ot+i)->pro,(ot+i)->pri,(ot+i)->amo);
      tag2=tag2+1;}
  if(tag2==0) printf("您没有订单\n");
  fclose(p2);}
 else if(tag1==0) printf("客户ID不存在\n");
 getchar();
 clrscr();

}

void calculate()
{FILE *p1,*p2;
 int i,j,t,m,tag1=0,tag2=0,l1,l2;
 long k1,k2;
 int num[20];
 char *ex,*ps1,*ps2,*tt;
 float sum=0,a,b;
 struct order {char ord[5];
        char spa1[3];
        char cus[5];
        char spa2[3];
        char dat[12];};
 struct ordet {char ord[5];
        char spa[7];
        char pro[13];
        char pri[13];
        char amo[6];};
 struct order *or;
 struct ordet *ot;
 if((p1=fopen("d:\\dzs\\order3.txt","rb"))==NULL)
  printf("error\n");
 printf("请输入客户ID:\n");
 ex=(char *)malloc(6);gets(ex);clrscr();
 fseek(p1,0l,2);k1=ftell(p1);ps1=(char *)malloc(k1);
 fseek(p1,0l,0);fread(ps1,1,k1,p1);l1=k1/28;
 for(i=0;i<l1;i++)
 {/**(ps1+26+i*28)='\0';*/*(ps1+27+i*28)='\0';*(ps1+5+i*28)='\0';
  *(ps1+7+i*28)='\0';*(ps1+13+i*28)='\0';*(ps1+15+i*28)='\0';/**(ps1+24+i*28)='\0';*/}
 or=(struct order *)ps1;
 for(i=0,j=0;i<l1;i++)
  if(strcmp(ex,(or+i)->cus)==0) {tag1=tag1+1;num[j++]=i;} fclose(p1);
 if(tag1!=0)
 {if((p2=fopen("d:\\dzs\\ordet.txt","rb"))==NULL)
   printf("error\n");
  fseek(p2,0l,2);k2=ftell(p2);ps2=(char *)malloc(k2);
  fseek(p2,0l,0);fread(ps2,1,k2,p2);l2=k2/44;
  for(i=0;i<l2;i++)
  {*(ps2+42+i*44)='\0';*(ps2+43+i*44)='\0';*(ps2+5+i*44)='\0';
   *(ps2+11+i*44)='\0';*(ps2+24+i*44)='\0';*(ps2+32+i*44)='\0';*(ps2+37+i*44)='\0';}
  ot=(struct ordet *)ps2;
  printf("********************************************************************************\n");
  printf("                         您的订单和订单明细如下\n");
  printf("\n");
  printf("********************************************************************************\n");
  for(j=0;j<tag1;j++)
   for(i=0;i<l2;i++)
    if(strcmp((ot+i)->ord,(or+num[j])->ord)==0)
     {printf("%s    %s     %s     %s     %s    %s   %s\n",(or+num[j])->ord,(or+num[j])->cus,(or+num[j])->dat,(ot+i)->pro,(ot+i)->pri,(ot+i)->amo);  
      b=atof((ot+i)->amo);a=atof((ot+i)->pri);
      sum=sum+a*b;
      tag2=tag2+1;}
  if(tag2==0) printf("您没有订单\n");
   else {printf("\n");
         printf("\n");
         printf("\n");
  printf("总成本为 %f\n",sum);}
  fclose(p2);}
 else if(tag1==0) printf("客户ID不存在\n");
 getchar();
 clrscr();


}


void menu()
{char x;
do
 {printf("\n          订单菜单                   \n");
  printf("               ******************************************** \n");
  printf("               *                                          * \n");
  printf("               *1.添加订单                                * \n");
  printf("               *                                          * \n");
  printf("               *2.查找订单和订单明细                      * \n");
  printf("               *                                          * \n");
  printf("               *3.加总                                    * \n");
  printf("               *                                          * \n");
  printf("               *4.退出                                    * \n");
  printf("               *                                          * \n");
  printf("               *                                          * \n");
  printf("               ******************************************** \n");
  x=getchar();getchar();
  clrscr();
  if(x=='1') add();
  if(x=='2') search();
  if(x=='3') calculate();
  if(x==4)   myprint();
  if(x!='1'&&x!='2'&&x!='3'&&x!=4) printf("please choose from 1 to 4 \n");
 }while(x!='4');
}


main()
{ char  choose,yes_no;

do
{  myprint();
   printf("                ");
   choose=getch();
   switch(choose)
{case'a':product();   break; 
 case'b':menu();   break;
 case'c':client();   break;
 case'd':   break;
 default :printf("\n    %c为非法选项!! \n",choose);
 }
   if(choose=='0')  break;
   printf("\n     要继续选择吗? (Y/N)?\n");
   do
   {  yes_no=getche();
   }  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("                 |           请输入选项编号(A-D):        |\n");
  printf("                 |-----------------------------------------|\n");
  printf("                 |               A----产品                 |\n");
  printf("                 |               B----订单                 |\n");
  printf("                 |               C----客户                 |\n");
  printf("                 |               D----退出                 |\n");
  printf("                 |-----------------------------------------|\n");
}
 
void product()
{char  choose,yes_no;

do
{  myprint1();
   printf("                ");
   choose=getch();
   switch(choose)
   {case'1':mydisplay();   break;
    case'2':mysearch();   break;
    case'3':mymodify();   break;
    case'4':myadd();   break;
    case'5':mydelete();   break;
    case'0':break; 
    default :printf("\n    %c为非法选项!! \n",choose);
   }
   if(choose=='0')  break;
   printf("\n     要继续选择吗? (Y/N)?\n");
   do
   {  yes_no=getche(); } 
    while (yes_no!='Y'&& yes_no!='y' && yes_no!='N' && yes_no!='n');
 } while(yes_no=='Y'||yes_no=='y');
}
void myprint1()
{ printf("\n\n\n\n\n\n\n\n");
  printf("                 *******************************************\n");
  printf("                 *          请输入选项编号(0-5):        *\n");
  printf("                 *******************************************\n");
  printf("                 *              1----显示产品              *\n");
  printf("                 *              2----查询产品              *\n");
  printf("                 *              3----修改产品              *\n");
  printf("                 *              4----添加产品              *\n");
  printf("                 *              5----删除产品              *\n");
  printf("                 *              0----退出                  *\n");
  printf("                 *******************************************\n");
}


/*显示产品信息的函数*/
 void mydisplay()
{int j=0;
  int i=0;int size;
  FILE *fp;
  fp=fopen("d:\\dzs\\产品.txt","r");
  while(feof(fp)==0)
  {fscanf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",&pro[j].id,&pro[j].name,&pro[j].gysh,&pro[j].lb,&pro[j].dwsl,&pro[j].dj,&pro[j].kcp,&pro[j].dgl,&pro[j].zdgl,&pro[j].zz);
   j++;
  }
  size=j-1;
  for(i=0;i<size;i=i+15)
 {printf("\n产品ID  产品名称 供给商      类别    单位数量      单价  库存  订购 再订购 终止\n\n" );
  for(j=0;j<15 && i+j<size;j++)
       {
   printf("%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s\n",pro[i+j].id,pro[i+j].name,pro[i+j].gysh,pro[i+j].lb,pro[i+j].dwsl,pro[i+j].dj,pro[i+j].kcp,pro[i+j].dgl,pro[i+j].zdgl,pro[i+j].zz);}
   printf("\n\n按任意键继续...\n"); 
   getche(); 
   }fclose(fp);
}
  void mysearch()
{int flag=0,n=0;
char proid[10]; FILE *fp;
 struct  product pro;
 fp=fopen("d:\\dzs\\产品.txt","rd");
 if(fp==NULL) {printf("\n                打开文件失败!\n"); return;}
 printf("\n                  请输入要查询产品的Id: ");
 scanf("%s",proid);
 while(feof(fp)==0)
  {fscanf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",&pro.id,&pro.n ame,&pro.gysh,&pro.lb,
&pro.dwsl,&pro.dj,&pro.kcp,&pro.dgl,&pro.zdgl,&pro.zz);
    if(strcmp(proid,pro.id)==0)
     {if(flag==0)
  {printf("\n产品ID  产品名称 供给商      类别    单位数量      单价  库存  订购 再订购 终止\n");
      printf("%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",pro.id,pro.name,pro.gysh,pro.lb,
pro.dwsl,pro.dj,pro.kcp,pro.dgl,pro.zdgl,pro.zz);
            flag=1;}}
        n++;
   }
   if(n==0) printf("\n          文件中无记录!\n");
 else if (flag==0) printf("\n              文件中无此产品!\n");
fclose(fp);}

void save(int size)
{ FILE *fp;
  int j;
  if((fp=fopen("d:\\dzs\\产品.txt","w"))==NULL)
     {printf("             打开文件失败\n");
     return;
  } 
 for(j=0;j<size+1;j++)
  fprintf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s\n",pro[j].id,pro[j].name,pro[j].gysh,pro[j].lb,pro[j].dwsl,pro[j].dj,pro[j].kcp,pro[j].dgl,pro[j].zdgl,pro[j].zz);
  fclose(fp);
  printf("         任意键继续....\n");
  getche();
}
void mymodify()
{ int i=0;
  int size;
  int flag=0,j=0;
  char tempnum[5];
  FILE *fp;
  fp=fopen("d:\\dzs\\产品.txt","r");
  while(feof(fp)==0)
  {fscanf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",&pro[i].id,&pro[i].name,&pro[i].gysh,&pro[i].lb,&pro[i].dwsl,&pro[i].dj,&pro[i].kcp,&pro[i].dgl,&pro[i].zdgl,&pro[i].zz);
   i++;}
   size=i;
   fclose(fp);
  printf("\n                   请输入要修改的产品ID号:");
 scanf("%s",tempnum);

  
   while(j<size-1)
  {if(strcmp(tempnum,pro[j].id)==0)
   if(flag==0)
     {printf("\n原记录信息:");
      printf("\n产品ID   产品名称  供给商 类别 单位数量     单价   库存品 订购量 再订购量 终止\n\n" );
      printf("%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s\n",pro[j].id,pro[j].name,pro[j].gysh,pro[j].lb,pro[j].dwsl,pro[j].dj,pro[j].kcp,pro[j].dgl,pro[j].zdgl,pro[j].zz);
      printf("\n\n         输入修改后的产品名称:");scanf("%s",pro[j].name);
      printf("\n       输入修改后的产品供给商代码:");scanf("%s",pro[j].gysh);
      printf("\n         输入修改后的产品类别代码:");scanf("%s",pro[j].lb);
      printf("\n         输入修改后的产品单位数量:");scanf("%s",pro[j].dwsl);
      printf("\n         输入修改后的产品单价:");scanf("%s",pro[j].dj);
      printf("\n         输入修改后的产品库存量:");scanf("%s",pro[j].kcp);
      printf("\n         输入修改后的产品订购量:");scanf("%s",pro[j].dgl);
      printf("\n         输入修改后的产品再订购量:");scanf("%s",pro[j].zdgl);
      printf("\n         输入修改后的产品终止信息(‘是’为终止):");scanf("%s",pro[j].zz);
    
    flag=1;}
    j++;
   }
   if(j==0) printf("\n          文件中无信息!\n");
   else if (flag==0) printf("\n              文件中无此产品!\n");
 
   save(size-1);
}

void  myadd()
{int i=0,j;char c;

 int  size;
 FILE *fp;
 fp=fopen("d:\\dzs\\产品.txt","r");
 while(feof(fp)==0)
  {fscanf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",&pro[i].id,&pro[i].name,&pro[i].gysh,&pro[i].lb,&pro[i].dwsl,&pro[i].dj,&pro[i].kcp,&pro[i].dgl,&pro[i].zdgl,&pro[i].zz);
   i++;}
   size=i;
   printf(" \n         现有产品数量为:%d",i);
   fclose(fp);
  
    
    loop: printf("\n      输入添加的产品ID:");scanf("%s",pro[size].id);           
     for(j=0;j<size;j++) 
     if(strcmp(pro[j].id,pro[size].id)==0)
     {printf("\n    id重复,请重新输入!");
      getche();
      goto loop;
      }
      printf("\n         输入添加的产品名称:");scanf("%s",pro[size].name);
      printf("\n         输入添加的产品供给商代码:");scanf("%s",pro[size].gysh);
      printf("\n         输入添加的产品类别代码:");scanf("%s",pro[size].lb);
      printf("\n         输入添加的产品单位数量:");scanf("%s",pro[size].dwsl);
      printf("\n         输入添加的产品单价:");scanf("%s",pro[size].dj);
      printf("\n         输入添加的产品库存量:");scanf("%s",pro[size].kcp);
      printf("\n         输入添加的产品订购量:");scanf("%s",pro[size].dgl);
      printf("\n         输入添加的产品再订购量:");scanf("%s",pro[size].zdgl);
      printf("\n         输入添加的产品终止信息(‘是’为终止):");scanf("%s",pro[size].zz);
     
save(size+1);


}


void mydelete()
{int flag=0,j=0,k,i=0,size,m;
 char tempnum[5];
  FILE *fp;
 fp=fopen("d:\\dzs\\产品.txt","r");
 if(fp==NULL) {printf("\n                打开文件失败!\n"); return;}
 
 while(feof(fp)==0)
  {fscanf(fp,"%3s%10s%10s%11s%11s%10s%5s%6s%6s%5s",&pro[i].id,&pro[i].name,&pro[i].gysh,&pro[i].lb,&pro[i].dwsl,&pro[i].dj,&pro[i].kcp,&pro[i].dgl,&pro[i].zdgl,&pro[i].zz);
   i++;}
   size=i;
  fclose(fp);
 
 
 printf("\n                   请输入要删除记录的产品ID号:");
 scanf("%s",tempnum);
 while(j<size+1)
  {if(strcmp(tempnum,pro[j].id)==0)
   if(flag==0)
    {flag=1;
     k=j; }
    j++;
  }
  if(j==0) {printf("\n          文件中无信息!\n");return;}
 else if (flag==0) {printf("\n              文件中无此产品!\n");return;}
 
 for(m=k;m<size+1;m++)
  {strcpy(pro[m].id,pro[m+1].id);
   strcpy(pro[m].name,pro[m+1].name);
   strcpy(pro[m].gysh,pro[m+1].gysh);
   strcpy(pro[m].lb,pro[m+1].lb);
   strcpy(pro[m].dwsl,pro[m+1].dwsl);
   strcpy(pro[m].dj,pro[m+1].dj);
   strcpy(pro[m].kcp,pro[m+1].kcp);
   strcpy(pro[m].dgl,pro[m+1].dgl);
   strcpy(pro[m].zdgl,pro[m+1].zdgl);
   strcpy(pro[m].zz,pro[m+1].zz);
  }
save(size-2);}


/*float transfer2(char *ca)
{float val,power,sum; int i=0,j;char s[20];
 printf("%s\n",*ca);
 for(i=0,j=0;i<13;i++)
  if(*(ca+i)='.'||(*(ca+i)>='0'&&*(ca+i)<='9')) s[j++]=*(ca+i);
 s[j]='\0';j=0;
 for(val=0;s[j]>='0'&&s[j]<='9';j++)
 val=10*val+s[j]-'0';
 if(s[j]=='.') j++;
 for(power=1;s[j]>='0'&&s[j]<='9';i++)
  {val=10*val+s[j]-'0'; power*=10;}

 sum=val/power;
 printf("%f\n",sum);
}*/
 

void cliread()          /*导入链表函数*/
     {int i,n=0;
 char ch;
 CLI *p1,*p2;
 /*float temp;   用来处理CLI.price的小数点后的数字*/

 if ((fpc=fopen("D:\\dzs\\client.txt","r"))==NULL)
     {
  printf("can not open file\n");
  exit(0);
     }

 p1=p2=(struct client *)malloc(sizeof(struct client));
  
 while(!feof(f pc))
  {
   while((ch=fgetc(fpc))==' ');
   
   p1->id[0]=ch; 
   i=0; 
   while((ch=fgetc(fpc))!=' ')
    p1->id[++i]=ch;  
   p1->id[++i]='\0';
                 
   
   while((ch=fgetc(fpc))==' ');  /*把读入的字符进行到没有空格的位置*/
   
   p1->name[0]=ch;  
   i=0;
   while((ch=fgetc(fpc))!=' ') 
    p1->name[++i]=ch;
   p1->name[++i]='\0';            /*数组结束标志*/
  
   while((ch=fgetc(fpc))==' ');   /*把读入的字符进行到没有空格的位置*/
   
   

   n++;
  
   if(n==1)
                     Chead=p1;
                     
   
   p1=(struct client*)malloc(sizeof(struct client));
        p2->next=p1; 
   p2=p1;
  }
 p2->next=NULL;
   


void clichoose()
    {char f;
     printf("                       请输入您的要求:                        \n");
        gotoxy(40,16);
        scanf("%c",&f);
           switch(f)
                {case'1':clidisplay();   break;
                 case'2':clisearch();    break;
                 case'3':cliadd();       break;
                 case'4':clidel();       break;
                 case'5':climodify();    break;
                 /*case'6':clisum();       break;*/
                 /*case'9':getchar();totalmenu();totalchoose();       break;*/
                 case'0':break; 
                 default:printf("\n    没有%c选项!! \n",f);
                }
     }

void cliprintmenu()
   {clrscr();
    printf("                 * * * * * * * * * * * * * * * * * * * * * *\n");
    printf("                 *                                         *\n");
    printf("                 *            客户信息治理系统             *\n");
    printf("                 *                  目录                   *\n"); 
    printf("                 *                                         *\n");
    printf("                 *            1    显示客户信息            *\n");
    printf("                 *            2    查询客户信息            *\n");
    printf("                 *            3    添加客户信息            *\n");
    printf("                 *            4    删除客户信息            *\n");
    printf("                 *            5    修改客户信息            *\n");
    printf("                 *            0    退出                    *\n");
    printf("                 *                                         *\n");
    printf("                 * * * * * * * * * * * * * * * * * * * * * *\n");
   }
void clidisplay()      /*显示链表函数*/
{
     char ch;
     int i,j;
     CLI *p;
    p=Chead;
    clrscr();
    getchar();                     /*接收输入的数字*/
   
    for(i=0;p->next!=NULL;i=i+19)
    {  
        clrscr();
        printf("客户ID                    客户公司    \n");
        for(j=0;j<18&&p->next!=NULL;j++)
        {
             
              printf("%6s   %25s \n",p->id,p->name);
              p=p->next;
        }
   
         printf("\nPress Enter to continue......\n"); 
         getchar();
           
     }       
         clireturn();
}

void cliadd()
     {
      CLI *p1,*p2;
     
     
      p2=(struct client *)malloc(sizeof(struct client));
     
      getchar();
        
         printf("\n       输入添加的客户ID:");
               {gets(p2->id);}
        
         printf("\n       输入添加的客户公司名称:");
               {gets(p2->name);}
        
        
      p2->next=Chead;
      Chead=p2;
        
     
     
      printf("\n               添加后数据                  \n");              
      printf("客户ID                    客户公司    \n");
      printf("%5s   %25s\n",p2->id,p2->name);


      printf("\nPress Enter to continue......\n");     
      getchar();         /*接收回车符*/
      clireturn();
     } 

void clidel()        
{     CLI *p1,*p2;
      char del_id[8];
      if(Chead==NULL)
      { 
         printf("\nList NULL!\n");
         exit(0);
      }
      clrscr();
      p1=Chead;
      printf("\n             请输入要删除的客户ID:               \n");
      gotoxy(36,2);
      getchar();                 /*接收选择目录的数字*/
      gets(del_id);
     
     
      while(strcmp(del_id,p1->id)!=0&&p1->next!=NULL) 
         {p2=p1;
          p1=p1->next;}                       /*p1后移一个节点*/
     
      if((p1->next==NULL)&&(strcmp(del_id,p1->id)==0))             /*找到了*/
          p2->next=NULL;
     
      else if((strcmp(del_id,p1->id)==0)&&(p1->next!=NULL))                        /*找到了*/
         {
          if(p1==Chead)   {Chead=Chead->next;}     /*若p1指向的是首节点,把第二个节点地址赋予Chead*/
          else p2->next=p1->next;
          printf("您已经删除了ID为%s的客户!\n",del_id);
         }
     
      else printf("没有ID为%s的客户!\n",del_id);
     
      printf("\nPress Enter to continue......\n");       
      getchar();
      clireturn();
}

void clisearch()
     {char i[8];
      CLI *p1;
      clrscr();
     
      printf("                 请输入所要查询的客户编号:");
      getchar();                 /*接收选择目录的数字*/     
      gets(i);
      p1=Chead;
     
      while(p1!=NULL&&(strcmp(i,p1->id)!=0))
          
                 {p1=p1->next;}
          

      if(p1==NULL) printf("              没有此编号的产品!");
      else
          {printf("客户ID                    客户公司    \n\n");
           printf("%6s   %25s\n",p1->id,p1->name);
          }
 printf("\nPress Enter to continue......\n"); 
      getchar();          
      clireturn();
     }


void climodify()
     {
      CLI *p1,*p2;
      char n[8];
      p1=Chead;
      printf("\n   请输入所要修改的客户编号:");
     
      getchar();                 /*接收选择目录的数字*/     
      gets(n);
     
      if((strcmp(n,p1->id)==0));
      else while((strcmp(n,p1->id)!=0)&&p1!=NULL)
                {p1=p1->next;}
      if(p1==NULL)    printf("找不到此条数据!");
      else
              {clrscr();
           printf("\n                  原数据:                         \n");
           printf("客户ID                    客户公司    \n\n");
           printf("%6s   %25s\n",p1->id,p1->name);


           printf("\n                  请修改!                          \n");
                 {gotoxy(2,5);
                              gets(p1->id);}
     
                 {gotoxy(27,5); 
                              gets(p1->name);}
     
     
         
           printf("\n                  修改后数据:                         \n");
           printf("客户ID                    客户公司    \n\n");
           printf("%6s   %25s\n",p1->id,p1->name);

           printf("                     修改成功!                       \n");
           }
     printf("\nPress Enter to continue......\n");
     getchar();
     clireturn(); 
}

void clireturn()
   {
    char r;
    clrscr();
    printf("\n         是否返回上级菜单(y/n):                     \n");
    gotoxy(32,2);
    scanf("%c",&r);
    getchar();         /*用来接收回车符*/
    switch(r)
      {
       case'y':clrscr();cliprintmenu();clichoose();   break;
       case'Y':clrscr();cliprintmenu();clichoose();   break;
       case'n':break;
       case'N':break;
       default:printf("\n    没有%c选项!! \n",r);
      }
    }
   
 client()
{
cliread();
cliprintmenu();
clichoose();

}

上一篇:{实例}tc下将画图保存为图片文件 人气:4831
下一篇:{实例}点阵的汉字程序 人气:5091
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058