| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 588 人关注过本帖
标题:怎么用linux里的make命令编译?
取消只看楼主 加入收藏
NIDHOGOO
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-12-2
收藏
 问题点数:0 回复次数:0 
怎么用linux里的make命令编译?
这是一个小商品管理系统的代码,想用linux的make命令来编译调试,但是不知道这个makefile文件怎么做,请教高手指教。代码如下:
这是顾客登陆模块
源文件:login.c
头文件:user.h

login.c
/*login.c:    顾客登录,判断顾客登录名、密码和权限,
根据权限调用相应功能选择界面*/
/*包含顾客信息头文件
包含创建顾客信息、增加、删除、修改、排序的顾客处理程序
包含管理员、普通顾客的功能选择界面处理程序*/
#include "user.h"
#include "cuser.c"
#include "admin.c"
#include "guest.c"
#include "adduser.c"
#include "deluser.c"
#include "sunum.c"
#include "munum.c"
int main( )
{
    FILE *fp = NULL;
    user Show;
    user Tmps;                                                                /*临时存放顾客信息的结构体变量*/
    char DataFile[40] = "yonghu";                                   /*存放顾客信息的文件名为yonghu*/
    int i;               
    char relogin;                                                             /*是否重新登录的标志*/
    int success=0;                                                           /*登陆成功的标志*/
    /*CreatUser( );*/
printf("#===========================================#\n");
printf("#   Welcome to the Product Management System!                            #\n");
printf("============================================#\n");
again:
     /*输入登录名*/
     printf("please enter the user name:");
     scanf("%s",Tmps.Name);
     


     /*输入密码,用不带回显的方式保证安全性*/
     printf("password=");
     for(i=0;i<6;i++)
          {
          Tmps.ps[i]=gatch( );
          }


     Tmps.ps[6]='\0';
     /*打开yonghu文件,用来验证登录名和密码*/
     fp=fopen(DataFile,"rb");
     if   (fp  ==  NULL)
     {
           printf("\nOpen file%sfail!End with any key \n",DataFile);
           perror("\OPen file fail");
           getch( );
           exit(1);
     }
     /*循环读取文件校验登录名和密码是否正确*/
     while(fread(&Show,sizeof(user),1,fp)    !=   (int)NULL)
     (
             /*如果通过验证,则将success成功登录标记设为1*/
             if((strcmp (Tmps.Name,Show.Name)==0)&&(strcmp(Tmps.ps,Show.ps)==0))
             {
                   printf("\nlogin successful!\n");
                   success=1;
                   /*判断权限,如power的值为1,则是管理员,并调用管理员功能选择界面*/
                   if(Show.power==1)
                        {
                        printf("\nyour power is administrator!\n");
                        admin( );/*调用管理员系统主控平台*/
                        )
                    /*判断权限,如power的值为0,则是普通顾客,并调用普通顾客功能选择界面*/
                    if(Show.power==0)
                             {
                              printf("\nyour power is user!\n");
                              Guest( );/*调用普通用户系统主控平台*/
                             }
                  }
      }
      /*如未能成功登录,让顾客选择重新登录或推出*/
      if(success==0)
            {
                     getchar( );
                      printf("\nerror user name or password!input again?(y/n)");
                      scanf("%c",&relogin);
                      if((relogin=='Y')!!(relogin=='y'))
                          {
                          printf("you choose input again:\n");
                          goto again;)
                      else
                           {
                                     printf("end program");
                                     getch( );
                                     exit(0);
                            }
                }
        }


user.h
/*===================user.h========================================*/
#include "stdio.h"
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define SIZE 100
typedef struct
{
   long Number;                                                                              /*顾客序号*/
   char Name[20];                                                                            /*顾客名称*/
   char ps[8];                                                                                   /*顾客密码*/
    int   power;                                                                                /*顾客权限*/
}user;
extern void Guest( );                                                                                                          /*普通客户功能选择界面*/
extern void Admin( );                                                                                                         /*管理员功能选择界面   */
extern void CreatUser( );                                                                                                    /*创建客户信息文件      */
extern void AddUser( );                                                                                                      /*增加顾客记录            */
extern void DelUser( );                                                                                                       /*删除客户记录            */
extern void ModifyByUserNumber( );                                                                                 /*根据顾客序号修改      */
extern void SortByUserNum( );                                                                                          /*根据顾客序号排序浏览*/

这个是商品信息管理模块的代码
程序清单(1):shead.h
#include "stdio.h"
#include "stdio.h"
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define SIZE 100 /* mac.ros definition*/
typedef struct
{
       long Number;                        /*Field of number            */
       char Name[20];                      /*Field of name               */
       float price;                             /*Field of price                */
       float discount;                       /*Field of discount           */
       float memberprice;                /*Field of memberprice   */
       }product;
       extern void CreatFile( );                                   /*创建信息文件*/
       extern void AddRecord( );                                /*增加            */
       extern void DelRecord( );                                 /*删除            */
       extern void ModifyByNumber( );                     /*修改            */
       extern void QueryBySeatNum( );                     /*按序号查询  */
       extern void QueryByName( );                          /*按姓名查询  */
       extern void SortByMemberprice( );                  /*按合计查询  */

程序清单(2):admin.c
/*admin.c:管理员功能选择界面,根据客户选项调用相应函数实现系统功能*/
#include "shead.h"
#include "creat.c"
#include "add.c"
#include "delete.c"
#include "modnum.c"
#include "qname.c"
#include "qseatnum.c"
#include "smprice.c"
void Admin( )
{
      int choice = 0;/*存放客户选项的变量*/
      /*====功能及操作的界面提示====*/
      while(1)
        {
               printf("--------------------------------------------------------------------------------------\n");
               printf("|                                                                                                                      |\n");
               printf("|                     Welcome to Product Management System                                 |\n");
               printf("|                                                                                                                       |\n");
               printf("|-------------------------------------------------------------------------------------|\n");
               printf ("|                    1. Init Product Information File                                                   |\n");
               printf("|                     2. AddProduct( )                                                                         |\n");
               printf("|                     3. DelProdut( )                                                                            |\n");
               printf("|                     4. QueryByProductName( )                                                          |\n");
               printf("|                     5. QueryByProductNum( )                                                            |\n");
               printf("|                     6. ModifyByProductNumber( )                                                     |\n");
               printf("|                     7. SortByMemberPrice( )                                                              |\n");
               printf("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
               printf("|                     System User Management                                                            |\n");
               printf("|                     11. CreatNewUserFile( )                                                                 |\n");
               printf("|                     12. AddUser( )                                                                               |\n");
               printf("|                     13. DelUser( )                                                                                |\n");
               printf("|                     14. ModifyUser( )                                                                          |\n");
               printf("|                     15. SortByUserNum( )                                                                    |\n");
               printf("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
               printf("|                       0. Exit System                                                                             |\n");
               printf("----------------------------------------------------------------------------------------\n");
               printf("#   Please Input Your Choose                                                                             #\n");
               printf("#   number 1~7 to Mange the Product Information                                           #\n");
               printf("#   number 11,12,13,14,15 to Mange the System User                                         #\n");
               printf("#   number 0 to Exit the System                                                                          #\n");
               printf("-----------------------------------------------------------------------------------------\n");
               scanf("%d",&choice);
               getchar( );
               /*根据客户选项调用相应函数*/
               switch(choice)
                    {   
                     case 1:
                         CreatFile( );
                         break;
                    case 2:                             
                         AddRecord( );
                         break;
                    case 3:
                         DelRecord( );
                         break;
                    case 4:
                         QueryByName( );
                         break;
                    case 5:
                         QueryBySeatNum( );
                         break;
                    case 6:
                         ModifyByNumber( );
                         break;
                    case 7:
                         SortByMemberPrice( );
                         break;
                    case 11:
                         CreatUser( );
                         break;
                    case 12:
                         AddUser( );
                         break;
                    case 13:
                         DelUser( );
                         break;
                    case 14:
                         ModifyByUserNumber( );
                         break;
                    case 15:
                         SortByUserNum( );
                         break;
                    

                    case 0:
                        exit(0);
                    default:
                        break;
                }
          }
}
程序清单(3):creat.c
/*creat.c:用于创建商品信息文件*/
#include "stdio.h"
/*函数CreatFile*/
void CreatFile( )
{
         FILE *fp = NULL;                                   /*定义指向文件的指针*/
         product Tmps;                                      /*定义进行操作时存放结构体变量的*/
         char DataFile[40] = "";                          /*存储商品信息的文件名*/
         int count = 1;                                       /*计算可输入数据的最大范围*/
         /*====输入存放商品信息的文件名====*/
         printf("\n please input new file name of product information.");
         printf("\n Notice:Name of file can't exceed 8 characters.suffix can't
exceed 3 characters,part of exceed will be discarded.\n");
         gets(DataFile);
         /*如顾客没有输入,则循环提示顾客输入*/
         while(*DataFile == ('\0'))
         {
               printf("\n please input new file name to store data,end with enter.");
               printf("\n Notice:Name of file can't exceed 8 characters,suffix can't
exceed 3 characters.part of exceed will be discarded.\n");
               gets(DataFile);
         }
         /*用二进制写的方式打开文件,即创建文件*/
         fp = fopen(DataFile,"wb+");
         /*如果当前文件不存在,提示打开文件失败*/
         if (fp == NULL)
         {
                printf("\n Open file %s fail!End with any key.\n",DataFile);
                printf("Open file fail");
         

                gatch( );
                exit(1);
          }
          /*如果成功打开或创建文件,则提示输入商品序号、名称、价格要素等相关信息*/
          printf("input product information record.number is 0 means input is end.\n");
          printf("Number is not exceed 9 figures,Name is not exceed 20 characters,range of grade:0.00~1000.00\n");
          /*循环从键盘上读取顾客输入的序号、名称、价格要素等相关信息*/
          while(count <= SIZE)
          {
          /*输入序号,如为0则停止输入*/
          printf("\n input 'number = 0' means end input .\n");
          printf("number=");
          scanf("%ld",&Tmps.Number);
          if (Tmps.Number == 0 )
              break;







           /*提示输入商品名称*/
           printf("name=");
           scanf("%s",Tmps,Name);

           /*提示输入商品的商品价格*/
           printf("price=");
           scanf("%f",&Tmps.price);

           /*提示输入商品折扣*/
           printf("discount=");
           scanf("%f",&TmpS.discount);
 
           /*用公式自动计算会员价*/
           TmpS.memberprice=TmpS.price*TmpS.discount;

           
           printf("\n");
           /*如遇无法写入文件的异常,则加以提示*/
           if(fwrite(&TmpS,sizeof(product),1,fp)!=1
           {
                  printf("\nwrite file %s fail!End with any key\n",DataFile);
                  perror("write file fail ");
                  getch( );
                  exit(1);
           }
}
count++;
}
/*如果输入的数据量超过最大允许的范围,则提示数据不能录入*/
if (count>SIZE)
    printf(*\nsorry,number of data can not exceed%d\n",SIZE);
fclose(fp);
/*====在屏幕上显示文件内容====*/
/*     clrscr( );*/
printf(*The data you input is store successful %s in file.\n*,DataFile);
printf("Countent as follow:\n");
fp=fpen(DataFile,"rb");
if (fp==NULL)
{
             printf("\nopen file%sfail!End with any key \n",DataFile);
             perror("Open file fail");
             getch( );
             exit(1);
}



printf("\nNumber\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
{
       printf("\n%ld\t%s\t%4.2f\t%4.2f\t\t4.2f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
}


fciose(fp);
}
程序清单(4):add.c
/*add.c:添加商品信息记录*/
#include "stdio.h"
void AddRecord( )
{
     FILE *fp = NULL;                                            /*定义指向文件的指针*/
     product TmpS;                                               /*定义进行操作时的临时结构体变量*/
     char DataFile[40] = "";                                    /*存储商品信息的文件名*/
     int count = 1;                                                 /*计算可输入数据的最大范围*/
     /*====输入要添加商品信息的文件名====*/
     printf("\n please input the product information file name to add record:");
     printf("\n Notice:Name of file can'texceed 8 characters.suffix can't
exceed 3 characters,part of exceed will be discarded.\n");
     gets(DataFile);
     /*如顾客没有输入,则循环提示顾客输入*/
     while(*DataFile == ('\0'))
     {
            printf(*\n please input new file name to store data,end with enter.");
            printf("\n Notice:Name of file can'texceed 8 characters,suffix can't
exceed 3 characters.part of exceed will be discarded.\n");
            gets(DataFile);
     }


     fp = fopen (DataFile,"a+");/*a+:当文件存在时,追加,当文件不存在时,创建*/
     /*如果当前文件不存在,提示打开文件失败*/
     if (fp == NULL)
     {
          printf(*\n Open file %s fail!End with any key.\n*,DataFile);
          perror("Open file fail");


          getch( );
          exit(1);
      }
      /*如果成功打开或创建文件,则提示输入商品序号、名称、价格要素等相关信息*/
       printf("input number,name and salary.number is 0 means input is end.\n");
       printf("Number is not exceed 9 figures,Name is not exceed 20 characters,range of grade:0.00~1000.00\n");
       /*循环从键盘上读取顾客输入的序号、名称、价格要素等相关信息*/
       while(count <=SIZE)
       {
              /*输入序号,如为0则停止输入*/
               printf("\n input 'number =0' means end input.\n");
               printf("number=");
               scanf("%ld",&TmpS.Number);
               if (TmpS.Number == 0 )
                   break;
              /*提示输入商品名称*/
              printf("name=");
              scanf("%s",TmpS.price);

              /*提示输入商品价格*/
              printf("price=");
              scanf("%f",&TmpS.price);

              /*提示输入商品折扣*/
              printf("discount=");
              scanf("%f",&TmpS.discount);
 
 
              /*用公式自动计算商品会员价*/
              TmpS.memberprice=TmpS.price*TmpS.discount;


              printf("\n");
              /*如遇无法写入文件的异常,则加以提示*/
              if(fwrite(&TmpS,sizeof(product),1,fp)!=1)
              {
                       printf("\nwrite file %s fail!End with any key\n",DataFile);
                       perror("Write file fail ");
                       getch( );
                       exit(1);
              }
              count++;
      }
      /*如果输入的数据量超过最大允许的范围,则提示数据不能录入*/
      if (count>SIZE)
          printf("\nsory,number of data can not exceed%d\n",SIZE);
      fclose(fp);
 






      /*====在屏幕上显示文件内容====*/
      /*       clrscr( );*/
      printf("The data you input is store successful %s in file.\n",DataFile);
      printf("Countent as follow:\n");


      fp=fopen(DataFile,"rb");
      if   (fp == NULL)
      {
            printf("\nOpen file%sfail!End with any key \n",DataFile);
            perror("Open file fail");
            getch( );
            exit(1);
       }


       printf("\nNumber\tName\tprice\tdiscountmemberprice\n");
       while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
       {
              printf(*\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,TmpS.Name,TmpS.price,TmpS.discount,Tmps.memberprice);
       }
 

       fclose(fp);
}
程序清单(5):delete.c
/*delete.c: 删除商品信息记录*/
#include "stdio.h"
void DelRecord( )
   {
      int i,j,k;
      long delnum;                                        /*存放顾客输入的要删除商品序号*/
      product TmpS;                                     /*定义进行操作时的临时结构体变量*/
      product s[SIZE];                                   /*SIZE,在shead.h头文件中定义的常量,值为100*/
      int recNumber;                                    /*原文件中的记录数*/
      char DataFile[40] = "",next;                  /*DataFile存储商品信息的文件名,next为是否进行下一次删除操作的选项*/
      FILE *fp;/*====fp指针指向存储数据的文件名====*/
      printf("\nplease input the name of production information file.\n");
      gets(DataFile);
      /*提示客户输入要进行删除记录的文件名*/
      while(*DataFile == ('\0'))
      {
             printf("\nplease input the name of production information file.\n");
             gets(DataFile);
      }
begin:
      /*以二进制读的方式打开文件*/
      fp=fopen(DataFile,"rb");
      if (fp == NULL)
      {
          printf("\nOpen file %s fail!End with any key\n",DataFile);
          perror("Open file fail");
          getch( );
          exit(1);
      }
      /*输入要删除的商品序号*/
      printf("please input the Product's seatnum which you will delete:");
      scanf("%ld",&delnum);
      printf("the product you will delete is:%ld\n",delnum);
      /*将文件中信息存入结构体数组*/
      /*与要删除的商品序号相匹配的项不写入数组,循环后数组中即为去掉了要删除记录后的剩余记录*/
      recNumber=0;
      while((fread(&TmpS,sizeof(product),1,fp)) != (int)NULL)
      {
            if(TmpS.Number!=delnum)
                   {
                   s[recNumber].Number = TmpS.Number;
                   strcpy(s[recNumber].Name,TmpS.Name);
                   s[recNumber].price = TmpS.price;
                   s[recNumber].discount = TmpS.discount;
                   s[recNumber].memberprice = TmpS.memberprice;
                   recNumber++;
                   }
      }
      fclose(fp);
            /*====将删除后的剩余结构体记录写入文件====*/
            fp=fopen(DataFile,"wb+");
            if (fp == NULL)
            {
            printf("\nSet up file %sfail !end with angkey.\n",DataFile);
            perror("Set up fail");
            getch( );
            exit(1);
       }
       for(i=0; i<recNumber; i++)
       {
            if(fwrite(&s[i],sizeof(product),1,fp)!=1)
            {
            printf("\nWrite file %s fail!end with angkey.\n",DataFile);
            perror("Write file fail!");
                   getch( );
                   exit(1);
            }
        }
        fcolse(fp);
/*====显示删除后的文件====*/
        fp=fopen(DataFile,"rb");
        if (fp == NULL)
        {
               printf("\nOpen file%sfail!End with angkey \n",DataFile);
               perror("Open file fail");
                   getch( );
                   exit(1);
            }
            printf("the file after delete is:\n");
            printf("\nNumber \t\tName\tprice\tdiscount\tmemberprice\n");
            while(fread(&TmpS,sizeof(product),1,fp) != (int)NULL)
            {
                   if(TmpS.Number!=0)


                   printf("\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
           }
           fclose(fp);
           /*询问客户是否继续删除*/
           printf("\nGo on ?(y/n)");
           next=getche( );
           putchar('\n');
           if ( next =='y' || next == 'y') goto begin;
        }
程序清单(6):modnum.c
/*********************************************************************/
  /* monnum.c : 修改商品信息记录                                              */
  /********************************************************************/
#include "stdio.h"
void ModifyByNumber( )
  {
      int i,j,k;
      long modnum;          /*存储客户输入的要修改的商品序号*/
      /*输入各项修改后的信息*/
      long Number;
      char Name[20];
      float price;
      float discount;
      float memberprice;
      product TmpS;    /*定义进行操作时的临时结构体变量*/
      product s[SIZE];/*SIZE,在shead.h头文件中定义的常量,值为100    */
      int recNumber;
      char DataFile[40] = "",next;
      /*DataFile存储商品信息的文件名,next为是否进行下一次删除操作的选项*/
      FILE *fp;/*====fp指针指向存储数据的文件名====*/
      /*提示客户输入要进行修改记录的文件名*/
      printf("\nplease input the name of file where data is stored,
end with enter key.\n");
      gets(DataFile);
      /*提示客户输入要进行修改记录的文件名*/
      while(*DataFile == ('\0'))
      {
      
      printf("\nplease input the name of file where data is stored,
end with enter key.\n");
      gets(DataFile);
      
      }
begin:
      /*以读的方式打开文件,如文件不存在,提示错误*/
      fp=fopen(DataFile,"rb");
      if    (fp == NULL)
      {
       printf("\nOpen file %s fail!End with any key\n",DataFile);
       perror("Open file fail");
       getch( );
       exit(1);
      }
printf("please input the Employee'seatnum which you will modify:");
scanf("%ld",&modnum);
printf("the product you will delete is:%ld\n,modnum");
/*输入要修改记录的各项内容值*/
Number=modnum;
printf("name=");
scanf("%s",Name);

printf("price=");
scanf("%f",&price);

printf("discount=");
scanf("%f",&discount);

/*用公式自动计算商品会员价*/
memberprice=peice*discount;
/*将文件中要修改的信息存入结构体数组*/
recNumber=0;
/*循环将文件数据读入结构体数组,
如文件中的数据商品号和要修改的商品号不符,则原样写入数组,
如文件中数据的商品号和要修改商品号匹配,
则根据顾客输入的各项修改内容重新赋值,即修改,并写入数组*/
while((fread(&TmpS,sizeof (product),1,fp)) != (int)NULL)
{
      if(TmpS.Number!=modnum)
             {
             s[recNumber].Number = TmpS.Number;
             strcpy(s[recNumber].Name,TmpS.Name);
             s[recNumber].price = TmpS.price;
             s[recNumber].discount = TmpS.discount;
             s[recNumber].memberprice = TmpS.memberprice;
             recNumber++;
             }
        else
             {
             s[recNumber].Number = Number;
             strcpy(s[recNumber].Name,Name);
             s[recNumber].price = price;
             s[recNumber].discount = discount;
             s[recNumber].memberprice = memberprice;
             recNumber++;
             }
}
fclose(fp);
/*====将修改后的结构体数组记录写入文件====*/
        fp=fopen(DataFile,"wb+");
        if    (fp == NULL)
        {
        printf("\nSet up file %sfail !end with anykey.\n",DataFile);
        perror("Set up fail");
        getch( );
        exit(1);
}


for(i=0; i<recNumber; i++)
{
    if(fwrite(&s[i],sizeof(product),1,fp)!=1)
    {
        printf("\nWrite file %s fail!end with anykey.\n",DataFile);
        perror("Write file fail!");
              getch( );
              exit(1);
   }
   }
   fclose(fp);
/*====显示修改后的文件====*/
fp=fopen(DataFile,"rb");
if    (fp == NULL)
{
      printf("\nOpen file%sfail!end with any key \n",DataFile);
      perror("Open file fail");
      getch( );
      exit(1);
}
printf("the file after modify is:\n");
printf("\nNumber\t\tName\tprice\tdiscount\tmemberprice\n");
while(fread(&TmpS,sizeof(produnt),1,fp) != (int)NULL)
{
      if(TmpS.Number!=0)
      printf("\n%ld\t%s\t%4.1f\t%4.1f\t%4.1f\n",TmpS.Number,
TmpS.Name,TmpS.price,TmpS.discount,TmpS.memberprice);
   }
   fclose(fp);
/*提示是否进行下一次修改*/
      printf("\nGo on ?(y/n)");
      next=getche( );
      putchar('\n');
      if( next =='y' || next =='y') goto begin;
   }
程序清单(7):qname.c
/*=======quame.c:按名称查询商品信息记录===============*/
#include  "stdio.h"
void  QueryByName()
(
     int result=0;/*"result=1"说明查询成功,反之查找失败*/
     product  TmpS;/*定义进行操作时的临时结构体变量*/
     

      
      char  Xingming[20];/*用户输入要查询的商品名称*/
      char  DateFile[40] = ""、next
       /*DateFile存储商品信息的文件名,next为是否进行下一次删除操作的选项*/
    FILE *fp=NULL;
    /*====fp指针指向存储数据的文件名====*/
    /*提示用户输入要查询的文件名*/
    printf("\nplease  input the name of product information  file .\n");
    gets(DateFile);
    /*提示用户输入要查询的文件名*/
    while(*DateFile == ('\0'))
    {
          printf("\nplease  input the name of product information  file .\n");
    gets(DateFile);
                        }
           /*提示用户输入要查询的文件名*/
     begin:
   result=0;
    printf("please input  the name  of product which  needs  look up (under 20 bit figure).\n");
    scanf("%s".&Xingming);
     getchar();
             /*以读方式打开文件*/   
       pf=fopen (DateFile ."r");
      if (fp=NULL)
      {
             printf("\nOpen file%sfale!Eed with any key .\n".DateFile);
         perror(open file fail");
        getch();
         exit(1);
               }
     /*循环查找和输入名称相匹配的商品信息记录,如果查找到,则输出结果*/
     while(feof(fp==0))
       {
             if(fread(&TmpS.sizeof(product).1,fp)!=(int)NULL)
         (
             if (stricmp(Tmps,Name,xingming)==0)
               {
                             printf ("\n  Find:)\n");
                printf("\nNumber=%ld  Name=%s  price=%4.if  discount=%4.if  meberprice=%4.if\n".TmpS.Number.Name.Tmps.price.TmpS.discount.TmpS.memberprice);
                                  result=1;/*"result=1"说明找到了该商品的对应信息.*/
                                  }
                                                   }
                                                   }
                     fclose(fp);
                            /*提示用户已查到结果并询问是否继续查找*/
               if (result ==  0 )
             {
                       printf("There  is no date of this product in the file!")
            }
           printf("\nGo on ?(y/n)");
           next=getche();
           putchar('\n');
            if  (next=='y'  ||  next =='y')goto  begin ;
                           }
程序清单(8):smprice.c
/*smemberprice.c:按商品会员价循序排序*/
 #include "stdio.h"
 void  SortByMenberPrice()
 {
   int i.j.k;
   product  Tmps;   /*定义进行操作时的临时结构体变量*/
  product s[SIZE];/*SIZE,在shead.h头文件中定义的常量,值为100*/
  int recNnmber =0
  char DateFile[40] =" ";  /*DateFile存储商品信息的文件名*/
  FILE  *fp ;/*====fp 指针指向存储数据的文件名====*、
    /*提示用户输入要进行排序的文件名*/
  printf("\nplease  input  the name of product information file.\n");
   get(DateFile);
 /*提示用户输入要进行排序的文件名*/
 while  (DateFile  == ('\0'))
   {
       printf("\nplease  input  the name of product information file.\n");
   get(DateFile);
    }
     /*以读的方式打开文件,如果文件不存在,提示错误*/
  fp =fopen(DateFile."rb");
  if (fp=NULL)
   {
     printf("\nopen  file %s  fail!End  with  any key\n".DateFile);
      perror("Open  file fail ");
    getch();
     exit();  
     }
     /*将文件重要排序的信息存入结构体数组*/
    while ((fread(&TmpS.sizeof(product).1.fp))!=(int)NULL)
   {
    s[reNumber].Number= TmpS.Number;
     strcpy(s[reNumber].Name.TmpS.Name);
     s[reNumber].price=TmpS.price;
      s[reNumber].discount=TmpS.discount;
           s[reNumber].memberprice=TmpS.memberprice;
          reNember++;
   }
   fclose(fp);
   /*===如果文件中有记录,则将各条记录按合计得排序===*/
   if(recNumber>1)
   {
           /*====用选择排序的方法进行合计得排序====*/
        for(i=0;i<recNumber-1;i++)
      {
                 k=i;
                for (j=i+1;j<reNumber;j++)
      {
     if (s[k].memberprice<s[j].membeprice)  k = j;
         }
        TmpS .Number =s[k].Number;
        strcpy(TmpS,Name.s[k].Name);
         TmpS .price=s[k].price;
           TmpS .discount=s=[k].discount;
             TmpS .memberprice =s[k].memberprice;
               

              
            s[k].Number=s[i].Number;
             strcpy(s[k].Name.s[i].Name);
              s[k].price=s[i].price;
            s[k].discount=s[i].discount;
            s[k].memberprice=s[i].memberprice;

         
           
           s[k].Number=TmpS.Number;
             strcpy(s[k].Name.TmpS.Name);
              s[k].price=TmpS.price;
            s[k].discount=TmpS.discount;
            s[k].memberprice=TmpS.memberprice;
                              }
                 /*====将排序好的结构体记录写入文件====*/
              fp=fopen(DateFile."wb+");
             if(fp==  NULL)
              {
               printf("\Set  up file %sfail !end with anykey .\n".DateFile);
                perror("Set  up   fail");
               getch();
               exit();
              }
               for(i=0;i<recNumberprice;i++)
            {
               if (fwrite(&s[i].sizeof(product).1.fp)!=1)
               {            
                printf("\nwrite file %sfail !end with anykey .\n".DateFile);
                perror("Write  file  fail  ");
               getch();
               exit();
              }
                    }
               fclose(fp);
                }
                   /*====显示排序后的文件====*/

                  printf("\the  product's  information  in file %s is as flow:.\n".DateFile);
                     fp =fopen(DateFile."rb");
                     if(fp==NULL)
                         {
                 printf("\nopen file %sfail !End with anykey .\n".DateFile);
                      perror("Open  file fail");
                     getch();
                     exit();
                 }
                printf("\nNumber\tName\tprice\tdiscount\tmemberprice\n");
             while(fread(&TmpS.sizeof(product).1.fp)!=(int)NULL)
    {
          printf("n%ld\t%s\t%4.2f\t%4.2f\t%4.2f\n".TmpS.Number.TmpS.Name.TmpS.price.TmpS.discount.TmpS.memberprice);
       }
          fclose(fp);
    }
搜索更多相关主题的帖子: make linux 命令 编译 
2008-12-02 16:05
快速回复:怎么用linux里的make命令编译?
数据加载中...
 
   



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

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