歡迎您光臨本站 註冊首頁

怎麼用linux里的make命令編譯?

←手機掃碼閱讀     火星人 @ 2014-03-26 , reply:0

這是一個小商品管理系統的代碼,想用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=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
#include
#include
#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
#include
#include
#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 {
if(fwrite(&s,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 {
if(fwrite(&s,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 {
k=i;
for (j=i+1;j {
if (s[k].memberprice }
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.Number;
strcpy(s[k].Name.s.Name);
s[k].price=s.price;
s[k].discount=s.discount;
s[k].memberprice=s.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 {
if (fwrite(&s.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);
}

[火星人 ] 怎麼用linux里的make命令編譯?已經有290次圍觀

http://coctec.com/docs/linux/show-post-185383.html